FormatDateTime 函数FormatDateTime function

返回格式为日期或时间的表达式。Returns an expression formatted as a date or time.

语法Syntax

FormatDateTime(Date、[ NamedFormat ])FormatDateTime(Date, [ NamedFormat ])


FormatDateTime 函数的语法包含以下部分:The FormatDateTime function syntax has these parts:

PartPart 说明Description
DateDate 必需。Required. 要设置格式的日期表达式。Date expression to be formatted.
NamedFormatNamedFormat 可选。Optional. 指示所使用的日期/时间格式的数值。Numeric value that indicates the date/time format used. 如果省略,则会使用 vbGeneralDateIf omitted, vbGeneralDate is used.

设置Settings

NamedFormat 参数具有以下设置:The NamedFormat argument has the following settings:

常量Constant Value 说明Description
vbGeneralDatevbGeneralDate 00 显示日期和/或时间。Display a date and/or time. 如果存在日期部分,则将其显示为短日期。If there is a date part, display it as a short date. 如果存在时间部分,则显示为长时间。If there is a time part, display it as a long time. 如果存在这两个部分,则这两个部分均会显示。If present, both parts are displayed.
vbLongDatevbLongDate 11 使用计算机的区域设置中指定的长日期格式显示日期。Display a date by using the long date format specified in your computer's regional settings.
vbShortDatevbShortDate 双面2 使用计算机的区域设置中指定的短日期格式显示日期。Display a date by using the short date format specified in your computer's regional settings.
vbLongTimevbLongTime 第三章3 使用计算机的区域设置中指定的时间格式显示时间。Display a time by using the time format specified in your computer's regional settings.
vbShortTimevbShortTime 44 使用24小时制 (hh: mm) 显示时间。Display a time by using the 24-hour format (hh:mm).

另请参阅See also

支持和反馈Support and feedback

有关于 Office VBA 或本文档的疑问或反馈?Have questions or feedback about Office VBA or this documentation? 请参阅 Office VBA 支持和反馈,获取有关如何接收支持和提供反馈的指南。Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.