I have a time in 24 hour format “14:00:00”.
For this date i want to generate date like if current time is less then 14:00:00 then today’s date else next day’s date.
so for “14:00:00”
if current date time is “30-10-2012 13:00:00” than I want 30-10-2012
else if current date time is “30-10-2012 15:00:00” than I want 31-10-2012
I tried this method that gives today’s date
public static String GetTodayDateTimeStamp(String time)
{
String toReturn = "";
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
Date date = new Date();
String toDayDate = dateFormat.format(date);
toReturn = toDayDate + " " + time;
return toReturn;
}
When creating a new
Dateobject, the current time will be assigned to it. If you create two of those objects and set the hour to 14 and the minutes, seconds (and milliseconds if you must) to 0 with the use of aCalendarinstance you’ll have the two dates you have to compare:Just in case, you might want to set the
lenientattribute of the calendar to true.