Meaningless Drivel is fun!*
The moose likes Java in General and the fly likes Date in Java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Date in Java" Watch "Date in Java" New topic
Author

Date in Java

Jay Ashar
Ranch Hand

Joined: Oct 13, 2002
Posts: 208
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?


SCJP 1.4<br />SCWCD 1.3
Stephen Huey
Ranch Hand

Joined: Jul 15, 2003
Posts: 618
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

Joined: Jan 30, 2000
Posts: 18671
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 ]

"I'm not back." - Bill Harding, Twister
Jay Ashar
Ranch Hand

Joined: Oct 13, 2002
Posts: 208
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Date in Java