使用 NSDateFormatter 格式化日期时出现问题
我有以下日期:
2011-09-09T18:01:47Z
我希望它显示为
“9/9/11 at 1:47PM”
无论正确的时间是什么
此代码返回一个空字符串:
NSLog(@"TIME: %@",[message valueForKey:@"created_at"]);
NSString* time = [message valueForKey:@"created_at"];
NSDateFormatter* dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"MM-dd-yy at HH:mm:ss"];
NSDate* newTime = [dateFormatter dateFromString:time];
[dateFormatter setDateFormat:@"MM-dd-yy at HH:mm:ss"];
NSString* finalTime = [dateFormatter stringFromDate:newTime];
I have the following date:
2011-09-09T18:01:47Z
I want it to appear as
"9/9/11 at 1:47PM"
whatever the correct time is
This code returns a null string:
NSLog(@"TIME: %@",[message valueForKey:@"created_at"]);
NSString* time = [message valueForKey:@"created_at"];
NSDateFormatter* dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"MM-dd-yy at HH:mm:ss"];
NSDate* newTime = [dateFormatter dateFromString:time];
[dateFormatter setDateFormat:@"MM-dd-yy at HH:mm:ss"];
NSString* finalTime = [dateFormatter stringFromDate:newTime];
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
两者的格式相同,它们与您的输入和输出几乎没有关系。遇到问题时,请参阅 Unicode 数据格式模式。
Your formatting is the same for both and they have little to no relation to your input and your output. Refer to the Unicode Data Format Patterns whenever you have issues.