🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.language
Article #18175

mystery of Date and Calendar classes

#18175
From: Arty Tsaturov
Date: Tue, 04 Aug 1998 00:00
30 lines
1178 bytes
Try this:

 Date myDate = new Date(0);
 Calendar myCalendar = Calendar.getInstance();
 myCalendar.setTime(myDate);

 System.out.println(myCalendar.get(myCalendar.YEAR));
 System.out.println(myCalendar.get(myCalendar.DAY_OF_YEAR));
 System.out.println(myCalendar.get(myCalendar.HOUR_OF_DAY));
 System.out.println(myCalendar.get(myCalendar.MINUTE));
 System.out.println(myCalendar.get(myCalendar.SECOND));

If you think you will get
Year: 1970
Day of the year: 1
Hour of Day: 0
Minute: 0
Second: 0

YOU ARE WRONG!!!!!
The result will be 
Year: 1969
Day of the year: 365
Hour 19
Minute 0
Second 0

Five hours offset...

Anybody has any clue???
Technical Details
Message-ID: <35C76F5F.2FD5@cscmail.csc.com>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f74b3,35b7d8d68dc9f18b,start
X-Google-Attributes: gidf74b3,public
From: Arty Tsaturov <atsaturo@cscmail.csc.com>
Subject: mystery of Date and Calendar classes
Date: 1998/08/04
Message-ID: <35C76F5F.2FD5@cscmail.csc.com>
X-Deja-AN: 377935778
Content-Transfer-Encoding: 7bit
Organization: Another Netscape Collabra Server User
Content-Type: text/plain; charset=us-ascii
Mime-Version: 1.0
Newsgroups: borland.public.jbuilder.java.language