[英]how to get the beginning of a day using Gregorian Calendar and Date in java
i am trying to mark date if the data created in the past 3 days.我正在尝试标记过去 3 天内创建的数据的日期。 I want to take the last 3 days, from the beginning (00:00).我想从一开始 (00:00) 开始的最后 3 天。
i have this code:我有这个代码:
int days = 3
GregorianCalendar gc=new GregorianCalendar();
gc.add(GregorianCalendar.DAY_OF_MONTH, -days);
if (timeCreated.before(gc.getTime())) {
return true;
}
return false;
if the current time is 16:00 clock i get the past 3 days, from 16:00 clock to now.如果当前时间是 16:00 时钟,我得到过去 3 天,从 16:00 时钟到现在。 I want to get from 00:00 3 days ago till now.我想从 3 天前的 00:00 到现在。
Thanks in advanced.先谢谢了。
set the hours, minutes and seconds in your calendar object to zero.将日历 object 中的小时、分钟和秒设置为零。
gc.set(GregorianCalendar.HOUR_OF_DAY, 0);
gc.set(GregorianCalendar.MINUTE, 0);
gc.set(GregorianCalendar.SECOND, 0);
gc.set(GregorianCalendar.MILLISECOND,0);
Remember to do this AFTER you have called gc.add
.请记住在调用gc.add
之后执行此操作。
try with尝试
gc.set(GregorianCalendar.HOUR_OF_DAY,0);
gc.set(GregorianCalendar.MINUTE,0);
gc.set(GregorianCalendar.SECOND,0);
gc.set(GregorianCalendar.MILLISECOND,0);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.