Ios Date Format: yyyy-MM-dd, iosyyyy-mm-dd

Source: Internet
Author: User
Tags month name

Ios Date Format: yyyy-MM-dd, iosyyyy-mm-dd

The date format displayed in the sample code does not conform to the localization habits. You can view the help documentation and modify it to a commonly used date format for future search;

NSDate * now = [NSDate date];

NSDateFormatter * df = [[NSDateFormatter alloc] init];
[Df setDateFormat: @ "yyyy-MM-dd"];

Self. dateLabel. text = [df stringFromDate: now];


// [NSDateFormatter localizedStringFromDate: now dateStyle: NSDateFormatterLongStyle timeStyle: NSDateFormatterNoStyle];


[Df setDateFormat: @ "HH: mm: ss"];

Self. timeLabel. text = [df stringFromDate: now];


// [NSDateFormatter localizedStringFromDate: now dateStyle: NSDateFormatterNoStyle timeStyle: NSDateFormatterLongStyle];


Date Format characters

(:)

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)


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.