How to handle different date time formats using NSDateFormatter

后端 未结 4 1934
时光说笑
时光说笑 2020-12-15 05:18

I have a String with a datetime format: \"YYYY-MM-DD HH:MM:SS\".

I use this in my source code:

NSDateFormatter *formatter = [[[NSDateFormatter alloc]         


        
4条回答
  •  感动是毒
    2020-12-15 06:03

    You want to use [NSFormatter dateFromString:] to convert your string-based date to an NSDate instance. From there you want to use stringFromDate with the NSDate, not the string as you have written above. I'm not sure about using the same NSDateFormatter for both parsing and formatting - you may need two separate instances to handle the different format styles.

提交回复
热议问题