Note that there are some explanatory texts on larger screens.

plurals
  1. POWhat is the default timezone for java.util.Calendar.?
    primarykey
    data
    text
    <p><strong>Code</strong></p> <pre><code>public String testDate(){ TimeZone.setDefault(TimeZone.getTimeZone("US/Eastern")); Calendar fromDate = Calendar.getInstance(); Date date= new Date(); System.out.println(fromDate); System.out.println(date); } </code></pre> <p>My calendar variable shows a cdate value <code>2013-12-09T00:00:00.000Z</code> and time value <code>1386649779590</code> while debugging the calendar variable below. </p> <pre><code>Calendar cal = Calendar.getInstance(); </code></pre> <p>Complete Calendar details which i have seen while printing the object</p> <pre><code>System.out.println(cal); </code></pre> <p><strong>Console</strong> </p> <pre><code>java.util.GregorianCalendar[time=1386649779590,areFieldsSet=true,areAllFieldsSet=true,lenient=true,zone=sun.util.calendar.ZoneInfo[id="US/Eastern",offset=-18000000,dstSavings=3600000,useDaylight=true,transitions=235,lastRule=java.util.SimpleTimeZone[id=US/Eastern,offset=-18000000,dstSavings=3600000,useDaylight=true,startYear=0,startMode=3,startMonth=2,startDay=8,startDayOfWeek=1,startTime=7200000,startTimeMode=0,endMode=3,endMonth=10,endDay=1,endDayOfWeek=1,endTime=7200000,endTimeMode=0]],firstDayOfWeek=1,minimalDaysInFirstWeek=1,ERA=1,YEAR=2013,MONTH=11,WEEK_OF_YEAR=50,WEEK_OF_MONTH=2,DAY_OF_MONTH=9,DAY_OF_YEAR=343,DAY_OF_WEEK=2,DAY_OF_WEEK_IN_MONTH=2,AM_PM=1,HOUR=11,HOUR_OF_DAY=23,MINUTE=29,SECOND=39,MILLISECOND=590,ZONE_OFFSET=-18000000,DST_OFFSET=0] </code></pre> <p>While my java.util.date variable shows a date as <code>Mon Dec 09 07:37:50 EST 2013</code>, while debugging the date variable</p> <pre><code>Date date= new Date(); </code></pre> <p>where as my default <code>timezone</code> that i have set is <strong>EST</strong> specified on program start</p> <pre><code>TimeZone.setDefault(TimeZone.getTimeZone("US/Eastern")); </code></pre> <p>And i am working from a <code>timezone</code> <strong>IST</strong>. </p> <p>My question is</p> <p><strong>Why is <code>cal</code> of <code>Calendar</code> and <code>date</code> of <code>Date()</code> different ?</strong></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload