• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Calendar-Wrong Day

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Somebody please run this piece of code. And tell me why the Day of the Week is
coming wrong:

import java.util.Calendar;
public class DateCalculation {
public static void main(String [] args){

Calendar startCal = Calendar.getInstance();
startCal.set(2004-1900,3-1,31); //for today (31/03/2004)
System.out.println("The day is : "+startCal.get(Calendar.DAY_OF_WEEK));
System.out.println("The date id : "+startCal.getTime());

}
}
[ March 31, 2004: Message edited by: Xon Bhuyan ]
 
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Howdy.
Your code outputs
The day is : 1
The date id : Sun Mar 31 12:08:08 GMT 0104
But changing the set call to:
startCal.set(2004,3-1,31)
outputs
The day is : 4
The date id : Wed Mar 31 12:09:58 BST 2004
 
Xon Bhuyan
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanx a lot.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic