我正在将一个Web应用程序开发到GWT中,并使用对象DatePicker。此对象以已定义的格式检索日期,我正在将该格式转换为字符串,例如:
Wed May 14 2014 00:00对于我来说,使用这个日期作为字符串对某些操作是有用的。然而,对于其中之一,我需要时间戳对象。因此,我以以下方式使用SimpleDateFormat对象:
SimpleDateFormat sdf = new SimpleDateFormat("E MMM dd yyyy HH:mm");
Timestamp tDateIni = new Timestamp(sdf.parse(sDateIni).getTime());然而,当我运行远程调试时,我会得到一个ParseException。你知道这个错误会是什么吗?我想我在使用"E“部分中的SimpleDateFormat对象的格式很糟糕,但我不确定。提前谢谢!
发布于 2014-05-29 12:06:26
我已经在SimpleDateFormat对象中添加了Locale对象,现在它可以工作了。感谢您的帮助和评论!
发布于 2014-05-27 10:38:51
如果您想在GWT中的客户端解析日期,那么尝试使用DateTimeFormat
DateTimeFormat dateTimeFormat=DateTimeFormat.getFormat("E MMM dd yyyy HH:mm");
Date date=dateTimeFormat.parse("Wed May 14 2014 00:00");如果要在服务器端解析日期,则以毫秒为单位从客户端传递时间为长值,而不是日期字符串,并使用new Date(timeInMills)在服务器端形成日期返回。
发布于 2014-05-27 10:32:09
把这个从
SimpleDateFormat sdf = new SimpleDateFormat("E MMM dd yyyy HH:mm");至
SimpleDateFormat sdf = new SimpleDateFormat("EEE MMM dd yyyy HH:mm");应该是EEE而不是E来表示Wed这样的工作日。
在下面的代码中,完美工作(测试了)
public static void main(String[] args) {
String s = "Wed May 14 2014 00:00";
SimpleDateFormat sdf = new SimpleDateFormat("EEE MMM dd yyyy HH:mm");
try {
Timestamp tDateIni = new Timestamp(sdf.parse(s).getTime());
System.out.println(tDateIni.getTime());
} catch (ParseException ex) {
System.out.println("Parse Error");
}
}https://stackoverflow.com/questions/23887023
复制相似问题