转换日期和时间字符串,ANDROID [英] Convert date and time to String, ANDROID
本文介绍了转换日期和时间字符串,ANDROID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有日期和时间格式
$日期:2013-02-19T11:20:16.393Z
和我可以转换格式正常,例如:
19.02.2013 11时20分16秒
解决方案
$日期:2013-02-19T11:20:16.393Z
所以你的实际格式是 ISO 8601
对于你的目标,你需要使用一些 DateFormatter 适当的模式和工作就完成了。
首先,你需要重写你的约会变成图案,从而
19.02.2013十一时20分16秒
等于 DD.MM.YYYY HH:MM:SS
所以,现在你需要使用格式化为例的 SimpleDateFormatter
执行转换。
伪code:
字符串源=2013-02-19T11:20:16.393Z
SimpleDateFormat的格式化=新的SimpleDateFormat(DD.MM.YYYY HH:MM:SS);
格式化的日期= NULL;
格式化= formatter.parse(源);
串formattedString = formatted.toString();
I have date and time this format
$date:2013-02-19T11:20:16.393Z
and I can convert normal format for example:
19.02.2013 11:20:16
解决方案
$date:2013-02-19T11:20:16.393Z
So your actual format is ISO 8601
For your goal you need to use some DateFormatter with proper pattern and work is done.
At first you need to rewrite your date into pattern so
19.02.2013 11:20:16
is equal to dd.MM.yyyy HH:mm:ss
So now you need to use formatter for example SimpleDateFormatter
that perform converting.
Pseudocode:
String source = "2013-02-19T11:20:16.393Z";
SimpleDateFormat formatter = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss");
Date formatted = null;
formatted = formatter.parse(source);
String formattedString = formatted.toString();
这篇关于转换日期和时间字符串,ANDROID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文