iOS date format Yyyy-mm-dd

Source: Internet
Author: User
Tags month name

See the sample code to show the date format, do not conform to localization habits, view the Help document, modified into the usual date format, records for later 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 Character description

(:)

The time separator character. In some locales, you can use other characters to represent time separators. The time separator separates hours, minutes, and seconds when formatting time values. The actual character used as the time separator in the formatted output is determined by the current culture value of your application.

(/)

The date separator character. In some locales, you can use other characters to represent the date separator. The date separator separates day, month, and year when formatting date values. The actual character used as the date separator in the formatted output is determined by the current culture of your application.

(%)

Used to indicate that no matter what letter is trailing, subsequent characters should be read in single-letter format. Also used to indicate that a single-letter format should be read in a user-defined format. For more detailed information, see the following.

D

Displays the day as a number without leading zeros (such as 1). If this is the only character in the user-defined number format, use%d.

Dd

Displays the day as a number with leading zeros (such as 01).

EEE

Displays the day as an abbreviated form (for example, Sun).

Eeee

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

M

Displays the month as a number without leading zeros (for example, January is represented as 1). If this is the only character in a user-defined number format, use%M.

Mm

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

MMM

Displays the month as an abbreviated form (for example, Jan).

MMMM

Displays the month as a full month name (for example, January).

Gg

Displays the era/era string (for example, A.D.)

H

Use a 12-hour system to display the hour as a number without leading zeros (for example, 1:15:15 PM). If this is the only character in a user-defined number format, use%h.

hh

Displays the hour as a number with leading zeros (for example, 01:15:15 PM) using a 12-hour system.

H

Displays the hour as a number without leading zeros, using a 24-hour system (for example, 1:15:15). If this is the only character in a user-defined number format, use%H.

HH

Displays the hour as a number with leading zeros using a 24-hour system (for example, 01:15:15).

M

Displays the minute as a number without leading zeros (for example, 12:1:15). If this is the only character in a user-defined number format, use%m.

Mm

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

S

Displays the seconds as a number without leading zeros (for example, 12:15:5). If this is the only character in a user-defined number format, use%s.

Ss

Displays the seconds as a number with leading zeros (for example, 12:15:05).

F

Displays the decimal part of the second. For example, the FF will be accurately displayed to 1% seconds, and the FFFF will be displayed exactly one out of 10,000 seconds. You can use up to seven F symbols in a user-defined format. If this is the only character in a user-defined number format, use%f.

T

Use a 12-hour system, and display uppercase A for any hour before noon, and display uppercase P for any hour between noon and 11:59 p.m. If this is the only character in a user-defined number format, use%t.

Tt

For locales that use the 12-hour system, uppercase AM is displayed for any hour before noon, and uppercase PM is displayed for any hour between noon and 11:59 p.m.

For locales that use the 24-hour format, no characters are displayed.

Y

Displays the year (0-9) as a number without leading zeros. If this is the only character in a user-defined number format, use%y.

Yy

Displays the year in a two-digit number format with a leading zero, if applicable.

yyy

Displays the year in four-digit number format.

yyyy

Displays the year in four-digit number format.

Z

Displays the time zone offset without leading zeros (for example,-8). If this is the only character in a user-defined number format, use%z.

Zz

Displays the time zone offset with leading zeros (for example-08)

zzz

Displays the full time zone offset (for example, -08:00)


iOS date format Yyyy-mm-dd

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.