Hil*_*amp 10
使用java.util.Date
类本身的方法:parse(String s)
和toString()
.虽然第一个被弃用,但它是与GWT一起使用的方法.如果您想要更好地控制Date的格式,请在转换为String时使用GWT特定的类:com.google.gwt.i18n.client.DateTimeFormat
.它将格式化给定模式的日期,类似于Java自己的日期SimpleDateFormat
.
import com.google.gwt.i18n.shared.DateTimeFormat;
import java.util.Date;
...
public Date getDate(String dateString) {
Date result = null;
try {
DateTimeFormat dateTimeFormat = DateTimeFormat.getFormat("yyyy-MM-dd");
result = dateTimeFormat.parse(dateString);
} catch (Exception e)
{
// ignore
}
return result;
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
8009 次 |
最近记录: |