| Author |
Java Current Date time compare
|
Ajay Tickle
Greenhorn
Joined: Mar 16, 2008
Posts: 17
|
|
Hi, I am getting date from database in format of 2008-03-30 14:20:07.0 and i have stored it in String. I want to compare it with current date time. As i am getting it from DB i cannot change the format. 1) Could you please tell me how to compare it with current date time 2) how to compare 2008-03-30 14:20:07.0 if I convert String to java.util.Date Thank you for help and time Ajay
|
 |
Jesper de Jong
Java Cowboy
Bartender
Joined: Aug 16, 2005
Posts: 12907
|
|
First of all, why are you getting it from the database as a string? Is it stored as a string in the database, or as a date, time or timestamp type? If it's the latter, you should get it as a java.sql.Date or java.sql.Timestamp: If there's really no other way then to get it as a string from the database, then you could parse the string into a java.util.Date object using java.text.SimpleDateFormat, and then you can use methods like before() and after() on the Date object to compare it to the current date.
|
Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
|
 |
 |
|
|
subject: Java Current Date time compare
|
|
|