format_datetime()format_datetime()
按提供的格式设置日期/时间格式。Formats a datetime according to the provided format.
format_datetime(datetime(2015-12-14 02:03:04.12345), 'y-M-d h:m:s.fffffff') == "15-12-14 2:3:4.1234500"
语法Syntax
format_datetime(
datetime ,
format)
format_datetime(
datetime ,
format)
参数Arguments
datetime
:datetime
类型的值。datetime
: value of a typedatetime
.format
:格式说明符字符串,由一个或多个格式元素组成。format
: format specifier string, consisting of one or more format elements.
返回Returns
包含格式结果的字符串。The string with the format result.
支持的格式Supported formats
格式说明符Format specifier | 描述Description | 示例Examples |
---|---|---|
d |
一个月中的某一天(1 到 31)。The day of the month, from 1 through 31. | 2009-06-01T13:45:30 -> 1、2009-06-15T13:45:30 -> 152009-06-01T13:45:30 -> 1, 2009-06-15T13:45:30 -> 15 |
dd |
一个月中的某一天(01 到 31)。The day of the month, from 01 through 31. | 2009-06-01T13:45:30 -> 01、2009-06-15T13:45:30 -> 152009-06-01T13:45:30 -> 01, 2009-06-15T13:45:30 -> 15 |
f |
日期和时间值的十分之几秒。The tenths of a second in a date and time value. | 2009-06-15T13:45:30.6170000 -> 6, 2009-06-15T13:45:30.05 -> 02009-06-15T13:45:30.6170000 -> 6, 2009-06-15T13:45:30.05 -> 0 |
ff |
日期和时间值的百分之几秒。The hundredths of a second in a date and time value. | 2009-06-15T13:45:30.6170000 -> 61, 2009-06-15T13:45:30.0050000 -> 002009-06-15T13:45:30.6170000 -> 61, 2009-06-15T13:45:30.0050000 -> 00 |
fff |
日期和时间值的千分之几秒。The milliseconds in a date and time value. | 6/15/2009 13:45:30.617 -> 617, 6/15/2009 13:45:30.0005 -> 0006/15/2009 13:45:30.617 -> 617, 6/15/2009 13:45:30.0005 -> 000 |
ffff |
日期和时间值的万分之几秒。The ten thousandths of a second in a date and time value. | 2009-06-15T13:45:30.6175000 -> 6175、2009-06-15T13:45:30.0000500 -> 00002009-06-15T13:45:30.6175000 -> 6175, 2009-06-15T13:45:30.0000500 -> 0000 |
fffff |
日期和时间值的十万分之几秒。The hundred thousandths of a second in a date and time value. | 2009-06-15T13:45:30.6175400 -> 61754、2009-06-15T13:45:30.000005 -> 000002009-06-15T13:45:30.6175400 -> 61754, 2009-06-15T13:45:30.000005 -> 00000 |
ffffff |
日期和时间值的百万分之几秒。The millionths of a second in a date and time value. | 2009-06-15T13:45:30.6175420 -> 617542、2009-06-15T13:45:30.0000005 -> 0000002009-06-15T13:45:30.6175420 -> 617542, 2009-06-15T13:45:30.0000005 -> 000000 |
fffffff |
日期和时间值的千万分之几秒。The ten millionths of a second in a date and time value. | 2009-06-15T13:45:30.6175425 -> 6175425、2009-06-15T13:45:30.0001150 -> 00011502009-06-15T13:45:30.6175425 -> 6175425, 2009-06-15T13:45:30.0001150 -> 0001150 |
F |
如果非零,则为日期和时间值的十分之几秒。If non-zero, the tenths of a second in a date and time value. | 2009-06-15T13:45:30.6170000 -> 6、2009-06-15T13:45:30.0500000 ->(无输出)2009-06-15T13:45:30.6170000 -> 6, 2009-06-15T13:45:30.0500000 -> (no output) |
FF |
如果非零,则为日期和时间值的百分之几秒。If non-zero, the hundredths of a second in a date and time value. | 2009-06-15T13:45:30.6170000 -> 61、2009-06-15T13:45:30.0050000 ->(无输出)2009-06-15T13:45:30.6170000 -> 61, 2009-06-15T13:45:30.0050000 -> (no output) |
FFF |
如果非零,则为日期和时间值的千分之几秒。If non-zero, the milliseconds in a date and time value. | 2009-06-15T13:45:30.6170000 -> 617、2009-06-15T13:45:30.0005000 ->(无输出)2009-06-15T13:45:30.6170000 -> 617, 2009-06-15T13:45:30.0005000 -> (no output) |
FFFF |
如果非零,则为日期和时间值的万分之几秒。If non-zero, the ten thousandths of a second in a date and time value. | 2009-06-15T13:45:30.5275000 -> 5275、2009-06-15T13:45:30.0000500 ->(无输出)2009-06-15T13:45:30.5275000 -> 5275, 2009-06-15T13:45:30.0000500 -> (no output) |
FFFFF |
如果非零,则为日期和时间值的十万分之几秒。If non-zero, the hundred thousandths of a second in a date and time value. | 2009-06-15T13:45:30.6175400 -> 61754、2009-06-15T13:45:30.0000050 ->(无输出)2009-06-15T13:45:30.6175400 -> 61754, 2009-06-15T13:45:30.0000050 -> (no output) |
FFFFFF |
如果非零,则为日期和时间值的百万分之几秒。If non-zero, the millionths of a second in a date and time value. | 2009-06-15T13:45:30.6175420 -> 617542、2009-06-15T13:45:30.0000005 ->(无输出)2009-06-15T13:45:30.6175420 -> 617542, 2009-06-15T13:45:30.0000005 -> (no output) |
FFFFFFF |
如果非零,则为日期和时间值的千万分之几秒。If non-zero, the ten millionths of a second in a date and time value. | 2009-06-15T13:45:30.6175425 -> 6175425、2009-06-15T13:45:30.0001150 -> 0001152009-06-15T13:45:30.6175425 -> 6175425, 2009-06-15T13:45:30.0001150 -> 000115 |
h |
采用 12 小时制的小时(从 1 到 12)。The hour, using a 12-hour clock from 1 to 12. | 2009-06-15T01:45:30 -> 1、2009-06-15T13:45:30 -> 12009-06-15T01:45:30 -> 1, 2009-06-15T13:45:30 -> 1 |
hh |
采用 12 小时制的小时(从 01 到 12)。The hour, using a 12-hour clock from 01 to 12. | 2009-06-15T01:45:30 -> 01、2009-06-15T13:45:30 -> 012009-06-15T01:45:30 -> 01, 2009-06-15T13:45:30 -> 01 |
H |
采用 24 小时制的小时(从 0 到 23)。The hour, using a 24-hour clock from 0 to 23. | 2009-06-15T01:45:30 -> 1、2009-06-15T13:45:30 -> 132009-06-15T01:45:30 -> 1, 2009-06-15T13:45:30 -> 13 |
HH |
采用 24 小时制的小时(从 00 到 23)。The hour, using a 24-hour clock from 00 to 23. | 2009-06-15T01:45:30 -> 01、2009-06-15T13:45:30 -> 132009-06-15T01:45:30 -> 01, 2009-06-15T13:45:30 -> 13 |
m |
分钟(0 到 59)。The minute, from 0 through 59. | 2009-06-15T01:09:30 -> 9、2009-06-15T13:29:30 -> 292009-06-15T01:09:30 -> 9, 2009-06-15T13:29:30 -> 29 |
mm |
分钟(00 到 59)。The minute, from 00 through 59. | 2009-06-15T01:09:30 -> 09、2009-06-15T01:45:30 -> 452009-06-15T01:09:30 -> 09, 2009-06-15T01:45:30 -> 45 |
M |
月份(1 到 12)。The month, from 1 through 12. | 2009-06-15T13:45:30 -> 62009-06-15T13:45:30 -> 6 |
MM |
月份(1 到 12)。The month, from 01 through 12. | 2009-06-15T13:45:30 -> 062009-06-15T13:45:30 -> 06 |
s |
秒(0 到 59)。The second, from 0 through 59. | 2009-06-15T13:45:09 -> 92009-06-15T13:45:09 -> 9 |
ss |
秒(00 到 59)。The second, from 00 through 59. | 2009-06-15T13:45:09 -> 092009-06-15T13:45:09 -> 09 |
y |
年份(0 到 99)。The year, from 0 to 99. | 0001-01-01T00:00:00 -> 1、0900-01-01T00:00:00 -> 0、1900-01-01T00:00:00 -> 0、2009-06-15T13:45:30 -> 9、2019-06-15T13:45:30 -> 190001-01-01T00:00:00 -> 1, 0900-01-01T00:00:00 -> 0, 1900-01-01T00:00:00 -> 0, 2009-06-15T13:45:30 -> 9, 2019-06-15T13:45:30 -> 19 |
yy |
年份(00 到 99)。The year, from 00 to 99. | 0001-01-01T00:00:00 -> 01、0900-01-01T00:00:00 -> 00、1900-01-01T00:00:00 -> 00、2019-06-15T13:45:30 -> 190001-01-01T00:00:00 -> 01, 0900-01-01T00:00:00 -> 00, 1900-01-01T00:00:00 -> 00, 2019-06-15T13:45:30 -> 19 |
yyyy |
由四位数字表示的年份。The year as a four-digit number. | 0001-01-01T00:00:00 -> 0001、0900-01-01T00:00:00 -> 0900、1900-01-01T00:00:00 -> 1900、2009-06-15T13:45:30 -> 20090001-01-01T00:00:00 -> 0001, 0900-01-01T00:00:00 -> 0900, 1900-01-01T00:00:00 -> 1900, 2009-06-15T13:45:30 -> 2009 |
tt |
上午/下午时间AM / PM hours | 2009-06-15T13:45:09 -> PM2009-06-15T13:45:09 -> PM |
支持的分隔符Supported delimeters
格式说明符可以包含以下分隔符字符:Format specifier can include following delimeters characters:
分隔符Delimeter | 评论Comment |
---|---|
' ' |
SpaceSpace |
'/' |
|
'-' |
短划线Dash |
':' |
|
',' |
|
'.' |
|
'_' |
|
'[' |
|
']' |
示例Examples
let dt = datetime(2017-01-29 09:00:05);
print
v1=format_datetime(dt,'yy-MM-dd [HH:mm:ss]'),
v2=format_datetime(dt, 'yyyy-M-dd [H:mm:ss]'),
v3=format_datetime(dt, 'yy-MM-dd [hh:mm:ss tt]')
v1v1 | v2v2 | v3v3 |
---|---|---|
17-01-29 [09:00:05]17-01-29 [09:00:05] | 2017-1-29 [9:00:05]2017-1-29 [9:00:05] | 17-01-29 [09:00:05 AM]17-01-29 [09:00:05 AM] |