Have been beating my head against this and not sure what I'm doing wrong here.
I am testing out the inDaylightTime() method for a certain time zone but it is returning "false" when it should be returning "true" in this case.
import java.util.TimeZone;
import java.util.Date;
public class TimeZoneDemo {
public static void main( String args[] ){
Date date = new Date(1380931200); // Sat, 05 Oct 2013, within daylight savings time.
System.out.println("In daylight saving time: " + TimeZone.getTimeZone("GMT-8:00").inDaylightTime(date));
}
}
This code keeps printing "false" when it seems clear that the result should be "true".
What am I missing here? Would appreciate any guidance.
You're specifying a time zone of GMT-8:00
- that's a fixed time zone, which is 8 hours behind of UTC permanently. It doesn't observe daylight saving time.
If you actually meant Pacific Time, you should specify America/Los_Angeles
as the time zone ID. Bear in mind that different time zones switch between standard and daylight saving time at different times of the year.
Additionally, new Date(1380931200)
is actually in January 1970 - you meant new Date(1380931200000L)
- don't forget that the number is milliseconds since the Unix epoch, not seconds.
See more on this question at Stackoverflow