字符串在Android的日期/时间对象字符串、对象、日期、时间

由网友(如果可以)分享简介:我有一个包含从Web服务返回的,像这样的日期/时间的字符串:字符串DTSTART =2010-10-15T09:27:37Z我如何获得这个成一个对象,如时间或日期?我最初想输出成不同的格式,但需要做其他的东西与它以后(即可能以不同的格式使用)。干杯解决方案 字符串DTSTART =2010-10-15T09:27:...

我有一个包含从Web服务返回的,像这样的日期/时间的字符串:

 字符串DTSTART =2010-10-15T09:27:37Z
 

我如何获得这个成一个对象,如时间或日期?我最初想输出成不同的格式,但需要做其他的东西与它以后(即可能以不同的格式使用)。

干杯

解决方案

 字符串DTSTART =2010-10-15T09:27:37Z;
SimpleDateFormat的格式=新的SimpleDateFormat(YYYY-MM-dd'T'HH:MM:ss'Z');
尝试 {
    日期日期= format.parse(DTSTART);
    的System.out.println(日期);
}赶上(ParseException的E){
    // TODO自动生成的catch块
    e.printStackTrace();
}
 

这是你在找什么。有现有的帖子这个问题。

python中字符串转换成时间对象 官方表

I have a string 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).

Cheers

解决方案

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) {  
    // TODO Auto-generated catch block  
    e.printStackTrace();  
}

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

阅读全文

相关推荐

最新文章