aspose file tools
The moose likes Java in General and the fly likes Java Current Date time compare Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "Java Current Date time compare" Watch "Java Current Date time compare" New topic
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
    
    3

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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Java Current Date time compare
 
Similar Threads
Java Date formatting problem
how do i compare row by row
how to get the oldest timestamp record in an array list
Problem with day light savings in Simple Date Formatter
Manipulation Date Time In RMS