Xub*_*per 4 format time android
我想像这样格式化时间:2011-05-11 11:22:33.
我有以下代码:
Time time = new Time(MobiSageUtility.TIMEZONE_STRING);
time.setToNow();
String timeStr= time.format("yyyy-MM-dd HH:mm:ss");
Run Code Online (Sandbox Code Playgroud)
但是,这给出的日期为:"yyyy-MM-dd HH:mm:ss"not "2011-05-11 11:22:33".在查看Android参考文档后,我尝试了以下代码:
String timeStr = time.format2445();
Run Code Online (Sandbox Code Playgroud)
但是这给出了一个字符串:20110511T112233.有人能告诉我如何正确格式化时间吗?
Pao*_*a G 23
String timeStr = time.format("%Y:%m:%d%H:%M:%S");
请参阅man strftime作为方法格式的doc解释:
http://linux.die.net/man/3/strftime
使用日期而不是时间,然后使用SimpleDateFormat。
例:
SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date date = new Date();
String dateString = fmt.format(date);
Run Code Online (Sandbox Code Playgroud)
http://download.oracle.com/javase/1.4.2/docs/api/java/text/SimpleDateFormat.html
| 归档时间: |
|
| 查看次数: |
13984 次 |
| 最近记录: |