开发者

Does the java date.before function take into account the timezone?

开发者 https://www.devze.com 2023-03-12 11:56 出处:网络
I have the timez开发者_C百科one set on the server to BST (British Daylight Savings Time), and the date being passed into the function was calculated in UTC.

I have the timez开发者_C百科one set on the server to BST (British Daylight Savings Time), and the date being passed into the function was calculated in UTC.

On the Java Oracle site, it simply refers to comparing the time as "now", but will this "now" time be the same timezone as set or will it be the one set on the server it is running on?


There is no timezone in the java.util.Date, it's effectively the timezone of the JVM it's running in.

My advice, if you need to work with timezones, use Joda


It's implied that java.util.Date always stores time in UTC. For instance if you call System.currentTimeMillis() or create new Date(), internal time will be in UTC. but Date.toString() will give different time for different default timezones.

So if you pass UTC date into before function, you will get correct result regardless of server time zone.

0

精彩评论

暂无评论...
验证码 换一张
取 消