IOS time format description

Source: Internet
Author: User
Tags month name

IOS time format description

In the iOS time stamp string NSdate conversion demo, we talked about

 

  1. -(IBAction) strToDate :( id) sender {
  2. NSString * timeStr = @ 15:00:00;
  3. NSDate * date = [NSDate dateFromString: timeStr format: @ yyyy-MM-dd HH: mm: ss];
  4. NSLog (@ string to NSDate: % @-> % @, timeStr, date );
  5. }

     

     

    So what is the time format of yyyy-MM-dd HH: mm: ss? After reading the following explanation, you will understand.

     

     

    One character

     

    (:)

    Time separator. In some region settings, you can use other characters to represent time delimiters. The time Delimiter is formatted every hour, minute, and second. The actual characters used as time delimiters In the formatted output are determined by the current regional value of your application.

    (/)

    Date separator. In some region settings, you can use other characters to represent the date separator. The date Delimiter is used to format the date value every day, month, and year. The actual Characters Used as the date Separator in the formatting output are determined by the current culture of your application.

    (%)

    It indicates that the subsequent characters should be read in single-letter format regardless of the trailing letter. It is also used to indicate that the single letter format should be read in the User-Defined Format. For more details, see the following content.

    D

    Display the day as a number without leading zero (for example, 1 ). If this is a unique character in the User-Defined number format, use % d.

    Dd

    Display the day as a number with a leading zero (for example, 01 ).

    EEE

    Display the day as an abbreviation (for example, Sun ).

    EEEE

    Display the day as the full name (for example, Sunday ).

    M

    Display the month as a number without leading zero (for example, January 1, January is expressed as 1 ). If this is a unique character in the User-Defined number format, use % M.

    MM

    Display the month as a number with a leading zero (for example, 01/12/01 ).

    MMM

    Display the month as an abbreviation (for example, Jan ).

    MMMM

    Display the month as the complete month name (for example, January ).

    Gg

    Display time/epoch strings (for example, A. D .)

    H

    Use the 12-hour system to display the hour as a number without leading zero (for example, 1:15:15 ). If this is a unique character in the User-Defined number format, use % h.

    Hh

    Use the 12-hour system to display the hour as a number with a leading zero (for example, 01:15:15 ).

    H

    Use the 24-hour system to display the hour as a number without leading zero (for example, 1:15:15 ). If this is a unique character in the User-Defined number format, use % H.

    HH

    Use the 24-hour system to display the hour as a number with a leading zero (for example, 01:15:15 ).

    M

    Display the minute as a number without leading zero (for example ). If this is a unique character in the User-Defined number format, use % m.

    Mm

    Display the minute as a number with a leading zero (for example, 12:01:15 ).

    S

    Display the second as a number without leading zero (for example ). If this is a unique character in the User-Defined number format, use % s.

    Ss

    Display seconds as numbers with leading zeros (for example, 12:15:05 ).

    F

    Displays the fractional part of the second. For example, ff is precisely displayed to 1% seconds, while ffff is precisely displayed to one in ten seconds. Up to seven f characters can be used in a user-defined format. If this is a unique character in the User-Defined number format, use % f.

    T

    In 12-hour format, uppercase A is displayed for any hour before noon, and uppercase P is displayed for any hour between noon and p.m. If this is a unique character in the User-Defined number format, use % t.

    Tt

    For region settings in the 12-hour format, the upper-case AM is displayed for any hour before noon, and the upper-case PM is displayed for any hour between noon and p.m.

    For regions in the 24-hour format, no characters are displayed.

    Y

    The year (0-9) is displayed as a number without leading zero. If this is a unique character in the User-Defined number format, use % y.

    Yy

    The year is displayed in the format of two digits with the leading zero (if applicable ).

    Yyy

    The year is displayed in the format of four digits.

    Yyyy

    The year is displayed in the format of four digits.

    Z

    Display the time zone offset without leading zero (for example,-8 ). If this is a unique character in the User-Defined number format, use % z.

    Zz

    Display the time zone offset with leading zero (for example,-08)

    Zzz

    Display the complete time zone offset (for example)

     

    Two-format display

    M/d/yy

    12/7/58

    D-MMM

    7-Dec

    D-MMMM-yy

    7-December-58

    D MMMM

    7 December

    MMMM yy

    December 58

    Hh: mm tt

    08:50 PM

    H: mm: ss t

    8:50:35 P

    H: mm

    20: 50

    H: mm: ss

    20:50:35

    M/d/yyyy H: mm

    12/7/1958 20:50


    3. After understanding the above concepts, you can convert the time into the format you want. If you have any questions, please leave a message to discuss it. Thank you!
    1. -(IBAction) strToDate :( id) sender {
    2. NSString * timeStr = @ 15:00:00;
    3. NSDate * date = [NSDate dateFromString: timeStr format: @ yyyy-MM-dd HH: mm: ss];
    4. NSLog (@ string to NSDate: % @-> % @, timeStr, date );
    5. }

       

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.