这段代码:
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());
给出结果:
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
如何从字符串创建日期,以便在同一时区将其与其他日期进行比较?