如何使用GWT 2.0.3將字符串轉換爲日期或日期爲字符串?將字符串轉換爲GWT上的日期
8
A
回答
10
使用java.util.Date
類本身的方法:parse(String s)
和toString()
。雖然第一個已被棄用,但它是與GWT一起使用的方法。如果您想更好地控制Date的格式,轉換爲String時使用GWT特定類:com.google.gwt.i18n.client.DateTimeFormat
。它會根據模式格式化日期,類似於Java自己的SimpleDateFormat
。
4
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;
}
1
要轉換日期的StringFormat
import com.google.gwt.i18n.shared.DateTimeFormat;
import java.util.Date;
...
public String getStringFormat(Date inputDate){
String strFormat = null;
try{
DateTimeFormat dateTimeFormat = DateTimeFormat.getFormat("DD-MMM-YYYY");
strFormat = dateTimeFormat.format(inputDate);
}catch(Exception e){
e.printStackTrace();
}
return strFormat;
}
相關問題
- 1. 將字符串轉換爲日期並將日期轉換回字符串
- 2. 將字符串轉換爲日期
- 3. 將字符串轉換爲日期php
- 4. 將字符串轉換爲日期
- 5. 將字符串轉換爲IST日期
- 6. 將日期轉換爲字符串
- 7. Swift將字符串轉換爲日期
- 8. 將日期轉換爲字符串
- 9. 將日期轉換爲字符串SQL
- 10. NSDateformatter將日期轉換爲字符串
- 11. Bash - 將字符串轉換爲日期
- 12. nsdateformatter ---將字符串轉換爲日期
- 13. 將字符串轉換爲日期
- 14. vb.net將字符串轉換爲日期
- 15. 將字符串轉換爲javascript日期
- 16. Sqlite將字符串轉換爲日期
- 17. 將字符串轉換爲日期
- 18. 將字符串日期轉換爲java.sql.Date
- 19. 將長字符串轉換爲日期
- 20. Ruby - 將字符串轉換爲日期
- 21. 將字符串轉換爲MySQL日期
- 22. 將字符串轉換爲日期
- 23. Stata:將字符串轉換爲日期
- 24. 將字符串轉換爲日期
- 25. Android將字符串轉換爲日期
- 26. 將JavaScript字符串轉換爲日期
- 27. 將字符串轉換爲日期C++
- 28. Java:將字符串轉換爲日期
- 29. PHP - 將字符串轉換爲日期
- 30. 將日期字符串轉換爲帶日期的ISO日期