在java中,什么时候开始一天? [英] In java, what time is the start of the day?

查看:79
本文介绍了在java中,什么时候开始一天?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一天的开始是什么时候,说01/01/2010?



是00:00:00:000吗?或者是午夜?





这可能是一个愚蠢的问题,但我很困惑,因为我使用Calendar.set(Calendar.HOUR,0),但这给我一个12:00:00的时间。



现在我意识到我应该使用HOUR_OF_DAY

解决方案

一天的开始并不总是午夜。它可以取决于时区和日期。 (如果时钟在一天开始的时候向前移动一小时,那将从凌晨1点开始。)



这就是为什么 Joda-Time 有一些类似 LocalDate.toDateTimeAtStartOfDay - 它们非常值得使用。



但是,通常是00:00:00是午夜。 (这也可以格式化为12am,具体取决于您的区域设置等。)


What time is the start of a day, say 01/01/2010?

Is it 00:00:00:000 ? or is that midnight?

[edit]

It might be a stupid question but I'm confused because I used Calendar.set(Calendar.HOUR, 0) but this gives me a time of 12:00:00.

and now I've realised I should be using HOUR_OF_DAY

解决方案

The start of the day isn't always midnight. It can depend on the time zone and date. (If the clock moves forward an hour at the start of the day, it will start at 1am.)

That's why Joda-Time has things like LocalDate.toDateTimeAtStartOfDay - and they're well worth using.

But yes, normally it's at 00:00:00 which is midnight. (This can also be formatted as "12am" depending on your locale etc.)

这篇关于在java中,什么时候开始一天?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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