Use of 5.1.8 strftime () and Strptime ()

Source: Internet
Author: User

The strftime () function is a function used to format a date, DateTime, and time, and supports date, date, time class, these date, DateTime, or time is represented by a string representation of the format character requirement. the strptime () function, In contrast, is the date time from the string representation to the corresponding datetime, as required by the formatted string.

For A Time object, the formatted string does not use the year, month, and day related characters because The time object does not have a corresponding value. If unfortunately used, only the default output is 0 values.

For a date object, the formatted string does not use time, minute, second, and microsecond-related characters because the date object does not have a corresponding value. If used, only the default output is 0 values.

Because the strftime () function is implemented by invoking the C language Lib library, it is supported on different platforms, specific platform-specific support details, You need to view the strftime Documentation description on the platform.

The following list conforms to the format characters of the C89 and C99 standards:

Format characters

Significance

Example

Precautions

%a

English abbreviations for the day of the week

Sun, Mon, ..., Sat (en_US); So, Mo, ..., Sa (De_de)

%A

The English name of the day of the week

Sunday, Monday, ..., Saturday (en_US)

%w

Day of the week with a digital representation, 0 6 means Saturday.

0 ... 6

 

%d

Two-digit date number supplemented with 0.

Inthe ... , to

%b

The month is represented by an abbreviated character.

Jan, Feb,..., Dec (en_US)

%B

The month is represented by a full name.

January, February, ..., December (en_US)

%m

Month with 0 two digits of the supplement.

01 ... 12

 

%y

year with 0 two digits of the supplement.

00 ... 99

 

% Y

in four-digit year.

0001 ... 2013 2014 2015 9998 9999

 

% H

0 Span style= "font-family: the song Body;" > added 24 hours represented by the hour.

00 ... 23

 

%I

Hours represented by a 0 Supplement of the Hour.

XX,... , A

%p

Local time is morning or afternoon.

AM,PM (en_US)

% M

0 Span style= "font-family: the song Body;" > The minute expression of the supplement.

00 ... 59

 

% S

0 Span style= "font-family: the song Body;" > The second expression of the supplement.

00 ... 59

 

%f

0 Span style= "font-family: the song Body;" > The additional microsecond representation.

000000, 000001 ... 999999

 

%z

The UTC offset is expressed as +hhmm or -hhmm.

(empty) , +0000,-0400,+1030

%Z

The time zone name.

(empty) , UTC , EST , CST

%j

The number of Days to supplement the year with 0.

001,002,... , 366

%u

The first week of the year, Sunday begins as a week.

XX,... , -

%W

The first week of the year, Monday begins as a week.

XX,... , -

%c

Use local appropriate date and time.

Tue 21:30:00 1988 (en_US)

%x

indicated by a local appropriate date.

08/16/88 (None);

08/16/1988 (en_US)

%%

Output percent %.

%

Example:

#python 3.4

Import datetime

TZ = Datetime.timezone (Datetime.timedelta (hours = 8))

DT = Datetime.datetime (1, Tzinfo=tz)

Print (TZ.UTC)

Print (Dt.strftime ('%A%z%u '))

The resulting output is as follows:

utc+00:00

Tuesday +0800 48


Cai Junsheng qq:9073204 Shenzhen

Use of 5.1.8 strftime () and Strptime ()

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.