Java 获取指定格式字符串的时间

                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

Calendar c = Calendar.getInstance();
System.out.println(sdf.format(c.getTime()));


Date nowTime = new Date(System.currentTimeMillis());

System.out.println(sdf.format(nowTime));

输出结果:

2018-03-26
2018-03-26

猜你喜欢

转载自blog.csdn.net/chuan_zhang_ak/article/details/79706422