aspose file tools*
The moose likes Beginning Java and the fly likes Calendar Method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Calendar Method" Watch "Calendar Method" New topic
Author

Calendar Method

Rajat Sarkar
Greenhorn

Joined: Sep 07, 2008
Posts: 18
import java.util.Calendar;

public class CalendarMethods
{
public static void main(String[] args)
{
Calendar c = Calendar.getInstance();
c.set(2009,1,24,10,2);
long day1 = c.getTimeInMillis();
day1+=1000*60*60;
c.setTimeInMillis(day1);
System.out.println("new hour : "+(c.HOUR_OF_DAY));
c.add(c.DATE,35);
System.out.println("add 35 days : "+c.getTime());
c.roll(c.DATE,35);
System.out.println("roll 35 days : "+c.getTime());
c.set(c.DATE,1);
System.out.println("set to 1 : "+c.getTime());
}
}


Output :
new hour : 11
add 35 days : Tue Mar 31 11:02:43 BST 2009
roll 35 days : Wed Mar 04 11:02:43 GMT 2009
set to 1 : Sun Mar 01 11:02:43 GMT 2009

why the first getTime() method shows BST while the other two shows GMT?
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39393
    
  28
What sort of Locale are you using? It was BST here on 31st March and GMT on 1st-4th March, so that looks correct to me for my own Locale. You have had automatic correction for summer time or daylight saving time.
Brian Legg
Ranch Hand

Joined: Nov 07, 2008
Posts: 488
Daylight savings.... I would have never thought of that Campbell!


SCJA
~Currently preparing for SCJP6
W. Joe Smith
Ranch Hand

Joined: Feb 10, 2009
Posts: 710
I was wondering if that was the answer, but I didn't know it switched from BST to GMT. I know we had a topic a while ago where someone was adding an hour right across the DST change and couldn't figure out why there was an extra hour being added. It was just ironic that the test case was at that exact time.


SCJA
When I die, I want people to look at me and say "Yeah, he might have been crazy, but that was one zarkin frood that knew where his towel was."
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39393
    
  28
In Britain it is very easy to remember:
From 1970-1971: Summer time all year until the last Sunday in October 1971, when 1:59:59am was followed immediately by 1:00:00am.
1971-about 10 years ago. Summer time from 3rd Sunday in March, when 1:59:59am was followed immediately by 3:00:00am, until last Sunday in October same as above.
About last 10 years (to conform to rest of European Union): Summer time from last Sunday in March until last Sunday in October, times as before.

I was possibly being sarcastic when I said "easy."
Mike Simmons
Ranch Hand

Joined: Mar 05, 2008
Posts: 3018
    
  10
Brian Legg wrote:Daylight savings.... I would have never thought of that Campbell!

Well, that is what BST refers to: British Summer Time. Daylight saving time for Great Britain.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Calendar Method