• 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
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

MY month is shown 1 month ahead.

 
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I feed a year, a month and a date into the int variables yy,mm,dd respectively and then call the code below. for example if I assign 2001 to yy and 1 to mm and 1 to dd the date it shows its Feb 1, 2001. Why is this happening?


calendar.set(yy,mm,dd);
java.util.Date date=calendar.getTime()

System.out.println(date); <- showing date 1 month ahead
 
Ranch Hand
Posts: 368
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You need to give the month as 0 if you want January.For e.g.

public static void main(String[] args) {
Calendar c = Calendar.getInstance();
c.set(2001,0,1);
java.util.Date date=c.getTime();
System.out.println(date);
}
O/P-> Mon Jan 01 03:12:44 GMT+05:30 2001
 
Tontang Bei
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you guys. I got very frustrated about this.
 
Remember to always leap before you look. But always take the time to smell the tiny ads:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic