objc NSDateformatter使用小插曲

来源:互联网 发布:泰兴减速机js txjsj 编辑:程序博客网 时间:2024/05/18 18:01

  今天在做项目的时候碰到一个看着很简单的问题就是将 如 :”2015/3/4 14:20:22" 这样的字符串数据 装换成 时间格式。

self.formatter = [[NSDateFormatteralloc] init];

self.formattersetLocale:[NSLocalecurrentLocale]];

self.formattersetDateFormat:@"yyyy/MM/dd hh:mm:ss"];

大概的代码,可是这样代码我怎么转换,返回的都是null,我无比纠结了。最后 才发现的,那个时间格式的是24小时制的,用该用 hh 改成 HH

self.formatter setDateFormat:@"yyyy/MM/dd HH:mm:ss"];


此格式转载:http://blog.csdn.net/gilnuy0106/article/details/8451911

iOS-NSDateFormatter 格式说明:

G: 公元时代,例如AD公元
    yy: 年的后2位
    yyyy: 完整年
    MM: 月,显示为1-12
    MMM: 月,显示为英文月份简写,如 Jan
    MMMM: 月,显示为英文月份全称,如 Janualy
    dd: 日,2位数表示,如02
    d: 日,1-2位显示,如 2
    EEE: 简写星期几,如Sun
    EEEE: 全写星期几,如Sunday
    aa: 上下午,AM/PM
    H: 时,24小时制,0-23
    K:时,12小时制,0-11
    m: 分,1-2位
    mm: 分,2位
    s: 秒,1-2位
    ss: 秒,2位
    S: 毫秒

0 0
原创粉丝点击