Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Calendar Method

 
Rajat Sarkar
Greenhorn
Posts: 18
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 47274
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 488
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Daylight savings.... I would have never thought of that Campbell!
 
W. Joe Smith
Ranch Hand
Posts: 710
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Campbell Ritchie
Sheriff
Pie
Posts: 47274
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3028
10
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic