• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Rob Spoor
  • Devaka Cooray
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Jj Roberts
  • Al Hobbs
  • Piet Souris

Calendar Method

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Marshal
Posts: 74341
334
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 488
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Daylight savings.... I would have never thought of that Campbell!
 
Ranch Hand
Posts: 710
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Marshal
Posts: 74341
334
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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."
 
Master Rancher
Posts: 4052
56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic