[英]Convert a date of String type to java.util.Date type without using SimpleDateFormat or Calendar
I'm fetching a date which is of String type but I need the Date type of it. 我正在获取一个String类型的日期,但是我需要它的Date类型。 I'm working in a gwt project so I cannot use SimpleDateFormat or Calendar (which doesn't work in the runtime and throws source code not found exception)
我在gwt项目中工作,因此无法使用SimpleDateFormat或Calendar(在运行时中不起作用,并抛出未找到源代码的异常)
new Date(stringDate) is deprecated so any other way I could do it? 不推荐使用新的Date(stringDate),所以我可以采用其他任何方式吗?
考虑使用DateTimeFormat: http : //www.gwtproject.org/javadoc/latest/com/google/gwt/i18n/client/DateTimeFormat.html
您可以从com.google.gwt.i18n.client
包http://www.gwtproject.org/javadoc/latest/com/google/gwt/i18n/shared/DateTimeFormat.html#使用DateTimeFormat
类的parse()
函数。解析%28java.lang.String 29%
Assuming you have a Date (java.sql.Date)
in the format yyy-mm-dd
you can call 假设您有一个
Date (java.sql.Date)
,格式为yyy-mm-dd
,则可以调用
Date.valueOf("1996-12-12")
which returns a Date
instance Date.valueOf("1996-12-12")
返回Date
实例
If you use Date (java.util.Date)
you can call 如果使用
Date (java.util.Date)
,则可以调用
new Date(System.currentTimeMillis())
which returns a Date
instance new Date(System.currentTimeMillis())
返回Date
实例
Edit GWT has DateTimeFormat which you can use 编辑 GWT具有DateTimeFormat可以使用
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.