我已经编写代码来获取时间和时间。当我跑步时,我无法长时间获得正确的日期时间。你能帮我解决这个问题吗?
TimeConverterUtil.java
import java.text.SimpleDateFormat;
import java.util.Date;
public class TimeConverterUtil
{
public static SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
public static SimpleDateFormat usrFormatter = new SimpleDateFormat("dd MMM yy, HH:mm:ss:ms");
public static String getDateTime(Long stamp)
{
Date date = new Date(stamp);
return formatter.format(date);
}
public static Long getTimestamp(String date)
{
Date lFromDate1;
try {
lFromDate1 = usrFormatter.parse(date);
return lFromDate1.getTime();
}
catch (Exception e)
{
e.printStackTrace();
return null;
}
}
}
测试程序:
TCTester.java
//$Id$
public class TCTester {
/**
* @param args
*/
public static void main(String[] args)
{
Long timeInLong = TimeConverterUtil.getTimestamp("28 Mar 13, 02:14:02:000");
System.out.println(TimeConverterUtil.getDateTime(timeInLong));
System.out.println("\n\n\n"+TimeConverterUtil.getTimestamp("28 Mar 13, 02:14:02:000"));
}
}