Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Date in Java

 
Jay Ashar
Ranch Hand
Posts: 208
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In my java class I get a date from database and I am then formatting it using this code
SimpleDateFormat formatter = new SimpleDateFormat ("yyyyMMddhhmm");
String duedate = formatter.format(duedate);
so now I have something like 200311211130.
I need to add 6 hours to this date, How can I do this? How can you add few hours of time to date?
 
Stephen Huey
Ranch Hand
Posts: 618
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First of all, most of the Date class has been deprecated. So, read up on the Calendar class and a concrete subclass called GregorianCalendar. There's plenty of example code and documentation for what you want to do. If you ever need to mess with databases and dates, then look at java.sql.Date. Have fun!
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First of all, most of the Date class has been deprecated.
Quite a few of the methods have been deprecated, but the remaining methods work just fine - and in this case, they're all you need:

[ November 21, 2003: Message edited by: Jim Yingst ]
 
Jay Ashar
Ranch Hand
Posts: 208
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jim,
Looks like this method which you gave me would do whatever I need to do for now. Its very helpful.
Thanks a lot guys, both of you.
Hetal.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic