Determine Whether Daylight Savings Time (DST) is Active in Java for a Specified Date

前端 未结 5 1053
生来不讨喜
生来不讨喜 2020-11-29 04:29

I have a Java class that takes in the latitude/longitude of a location and returns the GMT offset when daylight savings time is on and off. I am looking for an easy way to

5条回答
  •  不知归路
    2020-11-29 05:06

    This is the answer for the machine on which the question is being asked:

    TimeZone.getDefault().inDaylightTime( new Date() );
    

    A server trying to figure this out for a client will need the client's time zone. See @Powerlord answer for the reason why.

    For any particular TimeZone

    TimeZone.getTimeZone( "US/Alaska").inDaylightTime( new Date() );
    

提交回复
热议问题