• Post Reply Bookmark Topic Watch Topic
  • New Topic

Calendar-Wrong Day  RSS feed

 
Xon Bhuyan
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • 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 ]
 
Carlos Failde
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Thanx a lot.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!