1
我,如果有任何陷阱或像这样与普通的Java new Date()
新的Date()的结果并不总是正确
我用它在我的应用程序来获得当前时间戳疑惑。
但是,我看到(有时)结果出现了失误。像那些来自未来的日期..任何想法为什么这样的事情可能会发生?我还使用以下功能将此数据转换与串..
private final static SimpleDateFormat databaseDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
static
{
databaseDateFormat.setTimeZone(TimeZone.getTimeZone("gmt"));
}
public static String getDateConvertedToUTCDBString(Date date)
{
return databaseDateFormat.format(date);
}
public static Date getDateConvertedFromDBString(String date)
{
try
{
return localDatabaseDateFormat.parse(date);
}
catch(java.text.ParseException e)
{
return null;
}
}
宾果! http://www.codefutures.com/weblog/andygrove/2007/10/simpledateformat-and-thread-safety.html – katit 2012-02-17 04:52:27
这是Fortify曾经为我抓过的唯一有用的东西。这是完全正确的。 – Bishnu 2012-02-17 05:15:37