与字符串之类的NSDate格式分开时间? [英] Separate Time from NSDate format like string?

查看:88
本文介绍了与字符串之类的NSDate格式分开时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的日期字符串格式为2012-09-06 04:57:00.000。我需要在04:57 AM将该字符串中的时间分开。帮我解决这个问题?

I am having a Date String in this format "2012-09-06 04:57:00.000". I need to separate the time in that string in 04:57AM like that. help me out of this ?

推荐答案

NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"hh:mm:ss a"];
NSString *timeStr =  [formatter stringFromDate:[NSDate date]];

以上代码使用ARC,否则您需要发布格式化程序

The above code is with ARC otherwise you need to release formatter like

formatter release

这篇关于与字符串之类的NSDate格式分开时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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