NSDateFormatter date format, nsdateformatter

Source: Internet
Author: User
Tags julian day

NSDateFormatter date format, nsdateformatter

Statement of metadata:
G: AD
 
An example of the year:
Yy: two digits behind the year
Yyyy: indicates the complete year.
 
Monthly Statement:
M: The metric is 1 ~ 12, 1 digit or 2 digit
MM: The indicator is displayed as 01 ~ 12. Less than 2 digits will return 0
MMM: specifies the period of the English month, for example, Jan.
MMMM: full display of the English month, for example, January


Daily display:
D: The metric is 1 ~ 3, 1 bits or 2 bits
Dd: Percentage indicates 01 ~ 31. The number of less than two digits is 0.
 
Weekly display:
EEE: English week of the week, such as Sun
EEEE: Complete weekly English statement, for example, Sunday

 
Upper/afternoon display:
Aa: Indicates AM or PM


For example:
H: The percentage is 0 ~ (In 24 hours)
HH: The period is 00 ~ 23, less than 2 digits will return 0 (24 hours)
K: Percentage indicates 0 ~ 12, 1 digit or 2 digit (12 hour)
KK: Percentage indicates 0 ~ 12. Less than 2 digits will return 0 (12 hours)


The score is shown as follows:
M: 0 ~ 59,1 digit or 2 digit
Mm: 00 ~ 59. The number of less than two digits is 0.


Second display:
S: returns 0 ~ 59,1 digit or 2 digit
Ss: 00 ~ 59. The number of less than two digits is 0.
S: Display in milliseconds

An answer on Stackooverflow:

/*    x           number    xx          two digit number    xxx         abbreviated name    xxxx        full name    a           AM/PM    A           millisecond of day    c           day of week (c,cc,ccc,cccc)    d           day of month    e           day of week (e,EEE,EEEE)    F           week of month    g           julian day (since 1/1/4713 BC)    G           era designator (G=GGG,GGGG)    h           hour (1-12, zero padded)    H           hour (0-23, zero padded)    L           month of year (L,LL,LLL,LLLL)    m           minute of hour (0-59, zero padded)    M           month of year (M,MM,MMM,MMMM)    Q           quarter of year (Q,QQ,QQQ,QQQQ)    s           seconds of minute (0-59, zero padded)    S           fraction of second    u           zero padded year    v           general timezone (v=vvv,vvvv)    w           week of year (0-53, zero padded)    y           year (y,yy,yyyy)    z           specific timezone (z=zzz,zzzz)    Z           timezone offset +0000    sql         y-M-d H:m:s    rss         [E, ]d MMM y[y] H:m:s Z|z[zzz]*/

This is my comment for date parsing. I use the following, where toDateUsingFormat uses an NSDateFormatter with the passed in string. I do not use a locale, because rss dates are not localized.

    if ( 0 == [string rangeOfString:@","].length ) {        result = [string toDateUsingFormat:@"d MMM y H:m:s z"];    } else {        result = [string toDateUsingFormat:@"E, d MMM y H:m:s z"];    }

Edit:

I use getObjectValue: instead of dateFromString.

NSDate *result = nil;NSError *error = nil;[dataFormatter getObjectValue:&result forString:dateString errorDescription:&error];

Tips:

1. Set the time format to "MMM dd, yyyy". The "Mar. 24,2015 "(the simulator will not appear), just add this sentence with an extra point.

dateFormatter.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US"];


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.