NSDateFormatter for this format

╄→尐↘猪︶ㄣ 提交于 2019-12-13 22:29:10

问题


I want to make an NSDateFormatter object for this date format (for example):

2016-04-15 15:00:00

I've tried yyyy-mm-dd hh:mm:ss but then when I am trying to attach it to a date like that:

date = [formatter dateFromString:dateString];

It gives me nil.

what is the correct way to do it?

Thank you!


回答1:


set date format as

2016-04-15 15:00:00
yyyy-MM-dd HH:mm:ss

your date string is 24 hour format




回答2:


Here's all you need for date formatting: https://developer.apple.com/library/ios/documentation/Cocoa/Conceptual/DataFormatting/Articles/dfDateFormatting10_4.html

There's a list of link under the Fixed Format title where you can see in detail the different formats for whatever you want, for iOS7 and greater see this:

http://www.unicode.org/reports/tr35/tr35-31/tr35-dates.html#Date_Format_Patterns



来源:https://stackoverflow.com/questions/36647134/nsdateformatter-for-this-format

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!