Android 中的 ISO 8601 字符串到日期/时间对象 [英] ISO 8601 String to Date/Time object in Android

查看:53
本文介绍了Android 中的 ISO 8601 字符串到日期/时间对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个标准 ISO 8601 格式的字符串,其中包含从像这样的网络服务:

I have a string in standard ISO 8601 format that contains the date/time returned from a web service like so:

String dtStart = "2010-10-15T09:27:37Z"

如何将其放入诸如时间或日期之类的对象中?我最初想以不同的格式输出它,但稍后需要用它做其他事情(即可能以不同的格式使用).

How do I get this into an object such as Time or Date? I initially want to output it in a different format, but will need to do other stuff with it later (i.e. maybe use in a different format).

干杯

推荐答案

String dtStart = "2010-10-15T09:27:37Z";  
SimpleDateFormat  format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");  
try {  
    Date date = format.parse(dtStart);  
    System.out.println(date);  
} catch (ParseException e) {  
    e.printStackTrace();  
}

这就是你要找的.有关于这个问题的现有帖子.

This is what you are looking for. There is existing post about this problem.

这篇关于Android 中的 ISO 8601 字符串到日期/时间对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆