Time - Format

Time - Format - 图1 warning

Note: The gtime.Time object uses the Format method to achieve custom formatted date and time conversion, which conflicts with the Format method of the standard library time.Time. In the gtime.Time object, the Layout method is used to implement the Format format of the standard library time.Time, for example: t.Layout('2006-01-02 15:04:05').

Below is the list of time format syntax supported by the gtime module:

Format Description Example Return Value
Day — —
d Day of the month, 2 digits with leading zeros 01 to 31
D Day of the week, textual representation, 3 letters Mon to Sun
N ISO-8601 numeric representation of the day of the week 1 (Monday) to 7 (Sunday)
j Day of the month without leading zeros 1 to 31
l (“L” lowercase) Full textual representation of the day of the week Sunday to Saturday
S English suffix for the day of the month, 2 characters st, nd, rd, or th. Can be used with j
w Numeric representation of the day of the week 0 (Sunday) to 6 (Saturday)
z Day of the year 0 to 365
Week — —
W ISO-8601 week number of the year, starting on Monday e.g., 42 (42nd week of the year)
Month — —
F Full textual representation of a month January to December
m Numeric representation of a month, with leading zeros 01 to 12
M Short textual representation of a month, 3 letters Jan to Dec
n Numeric representation of a month, without leading zeros 1 to 12
t Number of days in the given month 28 to 31
Year — —
Y Full numeric representation of a year, 4 digits e.g., 1999 or 2003
y Two-digit representation of a year e.g., 99 or 03
Time — —
a Lowercase Ante meridiem and Post meridiem am or pm
A Uppercase Ante meridiem and Post meridiem AM or PM
g 12-hour format of an hour, without leading zeros 1 to 12
G 24-hour format of an hour, without leading zeros 0 to 23
h 12-hour format of an hour, with leading zeros 01 to 12
H 24-hour format of an hour, with leading zeros 00 to 23
i Minutes with leading zeros 00 to 59
s Seconds with leading zeros 00 to 59
u Milliseconds (3 digits) e.g., 000, 123, 239
U UNIX Timestamp (seconds) e.g., 1559648183
Timezone — —
O Difference to Greenwich time (GMT) in hours e.g., +0200
P Difference to Greenwich time (GMT) with colon between hours and minutes e.g., +02:00
T Timezone abbreviation e.g., UTC, GMT, CST
Date — —
c ISO 8601 date e.g., 2004-02-12T15:19:21+00:00
r RFC 822 formatted date e.g., Thu, 21 Dec 2000 16:01:07 +0200