Reputation: 87
I have a problem with a function to validate dates.
When I put a date to the time 2am, puts the
java.text.ParseException error: unparseable date: " 20050327020000 ",
however should put a different time if it works correctly and I returned: Sun Mar 27 1:00:00 CET 2005
.
I put the code below.
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;
public class Principal {
/**
* @param args
*/
public static void main(String[] args) {
try {
String format="yyyyMMddHHmmss";
String date = "20050327010000";
SimpleDateFormat sdf = new SimpleDateFormat(format);
sdf.setTimeZone(TimeZone.getDefault());
sdf.setLenient(false);
Date d = sdf.parse(date);
System.out.println("date parsed: " +d.toString());
} catch (Exception e) {
System.out.println("Exception: " +e.toString());
}
}
}
Upvotes: 3
Views: 371
Reputation: 206956
It's a daylight savings problem.
2005-03-27 02:00:00 is a date and time that does not exist in your timezone (CET) - in that night, daylight savings shifted, and the clock jumped from 01:59:59 to 03:00:00.
Upvotes: 5