• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to get a Date object with a specifed time  RSS feed

 
Dominic Choo
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have a problem on getting a Date object with
a specified time.
This is my piece of code:
============================================
Calendar cald = Calendar.getInstance();
cald.set(Integer.parseInt("23"), Integer.parseInt("08"), Integer.parseInt("2003"));

Date d = cald.getTime();
System.out.println("Date: " + d);
============================================
Why the result is "Wed Sep 23 08:12:22 SGT 2003"
and not "Wed Aug 23 08:12:22 SGT 2003"...???
Why the month is automatically increase by 1 ???
Thanks for any help.
Rgds,
Dominic
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The month doesn't "automatically increase" -- it's just that you have to specify the month using a zero-based index (i.e. January == 0, not 1.) All of the Java Date/Calendar/etc classes use this convention.
 
Dominic Choo
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Ernest, it works.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!