如何转换日期字符串,如 “2011-06-25T11:00:26+01:00”要长的像iphone吗?
我需要将此字符串日期“2011-06-25T11:00:26+01:00”转换为类似的长值。
我尝试了此操作
NSDateFormatter *df = [[[NSDateFormatter alloc] init] autorelease];
[df setTimeZone:[NSTimeZone timeZoneWithName:@"UTC"]];
[df setDateFormat:@"yyyy-MM-ddHH:mm:ssZ"];
NSDate *date = [df dateFromString:[time stringByReplacingOccurrencesOfString:@"T" withString:@""]];
[df setDateFormat:@"eee MMM dd, yyyy hh:mm"];
NSLog(@"time%@", time);
long lgTime = (long)[date timeIntervalSince1970];
,但这不起作用。请帮助我。
提前致谢。
I need to convert this string date "2011-06-25T11:00:26+01:00” into a long like value.
I tried this
NSDateFormatter *df = [[[NSDateFormatter alloc] init] autorelease];
[df setTimeZone:[NSTimeZone timeZoneWithName:@"UTC"]];
[df setDateFormat:@"yyyy-MM-ddHH:mm:ssZ"];
NSDate *date = [df dateFromString:[time stringByReplacingOccurrencesOfString:@"T" withString:@""]];
[df setDateFormat:@"eee MMM dd, yyyy hh:mm"];
NSLog(@"time%@", time);
long lgTime = (long)[date timeIntervalSince1970];
but this doesn't work. Please help me.
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
首先,我第一次错过了这个,但是
"2011-06-25T11:00:26+01:00"
无法解析。正确的字符串是"2011-06 -25T11:00:26+0100”
。获得该格式的字符串后,请使用日期格式 -
“yyyy-MM-dd'T'HH:mm:ssZ”
。用法示例
First of all, I missed this the first time but
"2011-06-25T11:00:26+01:00”
is cannot be parsed. The correct string would be"2011-06-25T11:00:26+0100”
.Once you've the string in that format, use the date format –
"yyyy-MM-dd'T'HH:mm:ssZ"
.Example usage
如果要将“2011-06-25T11:00:26+01:00”转换为“2011-06-25T11:00:26GMT+01:00”可以解析
希望这对你有帮助
If you want to convert "2011-06-25T11:00:26+01:00” to "2011-06-25T11:00:26GMT+01:00" which can be parsed
Hope this helps you