If i create a new Date() object. What will be the default timezone it will print.
I have my machine running in GMT. And i am creating a new Date() object. If i print why does it shows Thu Jul 05 08:21:05 PKT 2012. How does it takes the timezone as PKT ?
java. util. Date has no specific time zone, although its value is most commonly thought of in relation to UTC.
Unfortunately, there is no default time, so you have to change your time depending on the time zone used in the place.
Conclusion. Class java. util. Date stores a date-time value as milliseconds since the epoch.
Using Java 7 The Date class (which represents a specific instant in time) doesn't contain any time zone information.
The date itself doesn't have any time zone. Its toString()
method uses the current default time zone to return a String representing this date:
Date date = new Date(); System.out.println(TimeZone.getDefault()); System.out.println(date); TimeZone.setDefault(TimeZone.getTimeZone("UTC")); System.out.println(TimeZone.getDefault()); System.out.println(date);
Executing the above code on my machine leads to the following output:
sun.util.calendar.ZoneInfo[id="Europe/Paris",offset=3600000,dstSavings=3600000,useDaylight=true,transitions=184,lastRule=java.util.SimpleTimeZone[id=Europe/Paris,offset=3600000,dstSavings=3600000,useDaylight=true,startYear=0,startMode=2,startMonth=2,startDay=-1,startDayOfWeek=1,startTime=3600000,startTimeMode=2,endMode=2,endMonth=9,endDay=-1,endDayOfWeek=1,endTime=3600000,endTimeMode=2]] Fri Jul 06 09:24:45 CEST 2012 sun.util.calendar.ZoneInfo[id="UTC",offset=0,dstSavings=0,useDaylight=false,transitions=0,lastRule=null] Fri Jul 06 07:24:45 UTC 2012
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With