Convert ISO 8601 to NSDate

前端 未结 4 430
星月不相逢
星月不相逢 2020-12-03 01:02

I have a timestamp coming from server that looks like this:

2013-04-18T08:49:58.157+0000

I\'ve tried removing the colons, I\'ve tried all

4条回答
  •  南笙
    南笙 (楼主)
    2020-12-03 01:33

    I also have the native API, which is way cleaner... This is the implementation I got in my DateTimeManager class:

    + (NSDate *)getDateFromISO8601:(NSString *)strDate{
    
        NSISO8601DateFormatter *formatter = [[NSISO8601DateFormatter alloc] init];
        NSDate *date = [formatter dateFromString: strDate];
        return date;
    }
    

    Just copy and paste the method, it would do the trick. Enjoy it!

提交回复
热议问题