In what format is this date string?

前端 未结 2 1982
萌比男神i
萌比男神i 2020-12-11 06:35

Im trying to convert a bunch of NSStrings into NSDate objects. Here is an example string:

2013-04-25T15:51:30.427+1.00

But I can\'t figure

相关标签:
2条回答
  • 2020-12-11 06:52

    It is a valid date format as specified by ISO 8601, according to W3

    The formats are as follows. Exactly the components shown here must be present, with exactly this punctuation. Note that the "T" appears literally in the string, to indicate the beginning of the time element, as specified in ISO 8601.

    Year: YYYY (eg 1997) Year and month: YYYY-MM (eg 1997-07) Complete date: YYYY-MM-DD (eg 1997-07-16) Complete date plus hours and minutes: YYYY-MM-DDThh:mmTZD (eg 1997-07-16T19:20+01:00) Complete date plus hours, minutes and seconds: YYYY-MM-DDThh:mm:ssTZD (eg 1997-07-16T19:20:30+01:00) Complete date plus hours, minutes, seconds and a decimal fraction of a second YYYY-MM-DDThh:mm:ss.sTZD (eg 1997-07-16T19:20:30.45+01:00)

    where:

     YYYY = four-digit year
     MM   = two-digit month (01=January, etc.)
     DD   = two-digit day of month (01 through 31)
     hh   = two digits of hour (00 through 23) (am/pm NOT allowed)
     mm   = two digits of minute (00 through 59)
     ss   = two digits of second (00 through 59)
     s    = one or more digits representing a decimal fraction of a second
     TZD  = time zone designator (Z or +hh:mm or -hh:mm)
    

    In your case, the date has millisecond accuracy, try adding .sss to the format

    0 讨论(0)
  • 2020-12-11 06:57

    The proper format is yyyy-MM-dd'T'HH:mm:ss.SSSZZZZZ.

    See Unicode Date Format Patterns.

    Also, the ZZZZZ format for the +00:00 timezone format was added to iOS 6 and is not supported under iOS 5 or earlier.

    0 讨论(0)
提交回复
热议问题