Win a copy of Node.js Design Patterns: Design and implement production-grade Node.js applications using proven patterns and techniques this week in the Server-Side JavaScript and NodeJS forum!
  • 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
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

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.
reply
    Bookmark Topic Watch Topic
  • New Topic