This code:
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-DD_HH-mm-ss");
Date date=null;
try {
date = format.parse("2012-07-04_13-42-03");
} catch (Exception e) {
}
File file = new File("File.txt");
Date now=new Date();
Date last= new Date(file.lastModified());
System.out.println("exec:"+date+" "+date.getTime()+" "+date.getTimezoneOffset());
System.out.println(" now:"+now+" "+now.getTime()+" "+now.getTimezoneOffset());
System.out.println("last:"+last+" "+last.getTime()+" "+last.getTimezoneOffset());
gives the result:
exec:Wed Jan 04 13:42:03 CET 2012 1325680923000 -60
now:Wed Jul 04 13:42:20 CEST 2012 1341402140349 -120
last:Mon Jul 02 17:26:37 CEST 2012 1341242797000 -120
How can I create the date from the string so I can compare It with the rest, in the same timezone?
Ok,
so the problem wasn’t the timezone, but the conversion from
to
the problem is in the format pattern so changing
to
since D means Day in year and d means Day in month