Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xcode/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xcode 将字符串从xml转换为NSDate以及如何转换日期_Xcode_Nsdate_Xcode4.5_Nsdateformatter - Fatal编程技术网

Xcode 将字符串从xml转换为NSDate以及如何转换日期

Xcode 将字符串从xml转换为NSDate以及如何转换日期,xcode,nsdate,xcode4.5,nsdateformatter,Xcode,Nsdate,Xcode4.5,Nsdateformatter,这是我的数据字符串: <pubDate>Sun, 24 Mar 2013 00:42:13 +0200</pubDate> 我该怎么做才能让它工作?我读过几本指南,但都没有成功。这是你第一部分的答案 NSString *currentPubDate = @"Sun, 24 Mar 2013 00:42:13 +0200"; NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]init]; [dateForm

这是我的数据字符串:

<pubDate>Sun, 24 Mar 2013 00:42:13 +0200</pubDate>

我该怎么做才能让它工作?我读过几本指南,但都没有成功。

这是你第一部分的答案

NSString *currentPubDate = @"Sun, 24 Mar 2013 00:42:13 +0200";
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]init];

[dateFormatter setDateFormat:@"EEE, dd MMM yyyy HH:mm:ss Z"];
NSDate *date = [dateFormatter dateFromString:currentPubDate];
[dateFormatter setDateFormat:@"EEE, dd/M/yy HH:mm"];
NSLog(@"%@", [dateFormatter stringFromDate:date]);

对于翻译部分,您必须设置语言环境,但这在我的系统中也不起作用。

回答很好,尝试使用它来帮助我做什么,您有没有想过如何调整它?谢谢
NSString *currentPubDate = @"Sun, 24 Mar 2013 00:42:13 +0200";
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]init];

[dateFormatter setDateFormat:@"EEE, dd MMM yyyy HH:mm:ss Z"];
NSDate *date = [dateFormatter dateFromString:currentPubDate];
[dateFormatter setDateFormat:@"EEE, dd/M/yy HH:mm"];
NSLog(@"%@", [dateFormatter stringFromDate:date]);