本文介绍了2016-10-20T13的日期格式:01:47.317的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从字符串 2016-10-20T13:01:47.317 获取日期,但获得 nil

This is what I am trying for getting date from the string 2016-10-20T13:01:47.317 but getting nil

NSDateFormatter *dateFormatter1 = [[NSDateFormatter alloc] init];
dateString = [dateString substringToIndex:dateString.length - 3];
[dateFormatter1 setDateFormat:@"YYYY-MM-ddTHH:mm:ss"];
NSDate *date = [dateFormatter1 dateFromString:dateString]; 

还尝试了 yyyy ,但仍然没有。

我无法理解 .317 所以我从字符串中删除了它。这个日期格式是什么?

Also tried with yyyy but still getting nil.
I was not able to understand .317 so I eliminated that from the string. What shall be the date format for this ?

推荐答案

它.317表示毫秒使用 SSS

it .317 means milliseconds use SSS

NSDateFormatter *dateFormatter1 = [[NSDateFormatter alloc] init];
[dateFormatter1 setDateFormat:@"yyyy-MM-ddTHH:mm:ss.SSS"]; // or omit the timezone use `yyyy-MM-dd'T'HH:mm:ss.SSS`
 NSDate *date = [dateFormatter1 dateFromString:dateString]; 

这篇关于2016-10-20T13的日期格式:01:47.317的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-23 15:49