package com.test.desktop;
import java.util.Date;
import com.ibm.icu.text.SimpleDateFormat;
public class A {
public static Date getDateTime(String dateTimeStr) {
Date date = null;
try {
String separator = dateTimeStr.indexOf('/') > 0 ? "/" : "-";
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy" + separator + "MM" + separator+ "dd HH:mm:ss:sss");
date = simpleDateFormat.parse(dateTimeStr);
} catch (Exception e) {
System.out.println(e.getMessage());
}
return date;
}
/**
* @param args
*/
public static void main(String[] args) {
System.out.println(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss:sss").format(new Date()));
System.out.println(new Date());
System.out.println(new Date().getTime());
System.out.println("===========================================================");
System.out.println("2014-06-06 09:51:07:007");
System.out.println(new A().getDateTime("2014-06-06 09:51:07:007"));
System.out.println(new A().getDateTime("2014-06-06 09:51:07:007").getTime());
}
}
运行结果:
2014-06-06 09:51:07:007
Fri Jun 06 09:51:07 CST 2014
1402019467187
===========================================================
2014-06-06 09:51:07:007
Fri Jun 06 09:51:07 CST 2014
1402019467000
问题:
时间都是2014-06-06 09:51:07:007为什么getTime()结果不一样
------解决方案--------------------
你三次new Date() 时间就不一样