日期格式 FormatDateTime函数详解
FormatDateTime函数是一种经常使用的操作日期格式的函数,它用于将指定的日期值转换为指定的日期格式。
语法:
FormatDateTime(date, format)
参数:
- date:要格式化的日期值。
- format:指定的日期格式。可以是以下几种格式之一:
- "d":短日期格式,仅显示日期。
- "D":永日期格式,显示日期和星期。
- "t":短时间格式,仅显示时间。
- "T":长时间格式,显示时间和秒。
- "f":永日期+短时间格式。
- "F":永日期+长时间格式。
- "g":短日期+短时间格式。
- "G":短日期+长时间格式。
- "M":月份和日期格式。
- "R":RFC1123格式,如"ddd, dd MMM yyyy HH':'mm':'ss 'GMT'"。
- "s":可排序日期和时间格式,如"yyyy'-'MM'-'dd'T'HH':'mm':'ss"。
- "u":通用可排序日期和时间格式,如"yyyy'-'MM'-'dd HH':'mm':'ss'Z'"。
- "U":通用可排序日期和时间格式,如"yyyy'-'MM'-'dd HH':'mm':'ss'Z'"(UTC时间)。
- "Y":年份和月份格式。
返回值:
返回格式化后的日期字符串。
示例:
- FormatDateTime(#2022-01-01#, "d") 返回 "1/1/2022"
- FormatDateTime(#2022-01-01#, "D") 返回 "Saturday, January 1, 2022"
- FormatDateTime(#2022-01-01 12:34:56#, "t") 返回 "12:34 PM"
- FormatDateTime(#2022-01-01 12:34:56#, "T") 返回 "12:34:56 PM"
- FormatDateTime(#2022-01-01 12:34:56#, "f") 返回 "Saturday, January 1, 2022 12:34 PM"
- FormatDateTime(#2022-01-01 12:34:56#, "F") 返回 "Saturday, January 1, 2022 12:34:56 PM"
- FormatDateTime(#2022-01-01 12:34:56#, "g") 返回 "1/1/2022 12:34 PM"
- FormatDateTime(#2022-01-01 12:34:56#, "G") 返回 "1/1/2022 12:34:56 PM"
- FormatDateTime(#2022-01-01#, "M") 返回 "January 1"
- FormatDateTime(#2022-01-01#, "R") 返回 "Sat, 01 Jan 2022 00:00:00 GMT"
- FormatDateTime(#2022-01-01#, "s") 返回 "2022-01-01T00:00:00"
- FormatDateTime(#2022-01-01#, "u") 返回 "2022-01-01 00:00:00Z"
- FormatDateTime(#2022-01-01#, "U") 返回 "2022-01-01 00:00:00Z"
- FormatDateTime(#2022-01-01#, "Y") 返回 "January, 2022"
TOP