Java日历获取当前日期,不带小时、分钟、秒和毫秒,以毫秒为单位 [英] Java calendar get the current date, without hours, minutes, seconds and milliseconds, in milliseconds

查看:136
本文介绍了Java日历获取当前日期,不带小时、分钟、秒和毫秒,以毫秒为单位的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想以毫秒为单位获取当前日期,只有年、月和日期.但是当我使用这段代码时:

I would like to get the current date in milliseconds with only year, month and date. But when I use this code:

Calendar cal = Calendar.getInstance();
cal.clear(Calendar.HOUR);
cal.clear(Calendar.MINUTE);
cal.clear(Calendar.SECOND);
cal.clear(Calendar.MILLISECOND);
currentDate = cal.getTimeInMillis();

我仍然以毫秒为单位获得时间.我该如何解决这个问题?

I still get the time in milliseconds with the hour. How can I fix this?

推荐答案

Calendar cal = Calendar.getInstance();
cal.set(Calendar.HOUR_OF_DAY, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
currentDate = cal.getTimeInMillis();

请注意日历的时区.

这篇关于Java日历获取当前日期,不带小时、分钟、秒和毫秒,以毫秒为单位的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆