iPhone: How to convert “yyyyMMddThhmmss” format string to NSDate?

前端 未结 3 1499
悲&欢浪女
悲&欢浪女 2021-01-15 21:51

I have a string like \"20121124T103000\" and I want to convert this to NSDate.

I tried converting it with dateFormatter date format \"

3条回答
  •  旧巷少年郎
    2021-01-15 22:11

    Your original code is quite close; instead of:

    @"yyyyMMddThhmmss"
    

    You should be using:

    @"yyyyMMdd'T'hhmmss"
    

    The only difference is the pair of single quotes around the 'T' in the string- you just need to let the app know that 'T' is a part of the formatting, not the actual date.

提交回复
热议问题