EXCEL VBA 时间值格式 (hh:mm am/pm)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16681900/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
EXCEL VBA Timevalue format (hh:mm am/pm)
提问by 4 Leave Cover
How do I set the format for timevalue for 12-hour clock without second. For example: hh:mm AM/PM. Right now I'm using Format(TimeValue(Now), "hh:mm")
but it wont display AM/PM.
如何设置没有秒的 12 小时制时间值的格式。例如:hh:mm AM/PM。现在我正在使用,Format(TimeValue(Now), "hh:mm")
但它不会显示 AM/PM。
Thanks in advance.
提前致谢。
回答by Ken White
Change your format string to include the indicator for AM/PM
(based on the VBA Format function documentation- see the heading User-Defined Date/Time Formats (Format Function)
roughly halfway down the page - there's no anchor to link to directly):
更改您的格式字符串以包含以下指标AM/PM
(基于VBA 格式函数文档- 请参阅User-Defined Date/Time Formats (Format Function)
页面大约一半的标题- 没有可直接链接的锚点):
Format(TimeValue(Now), 'hh:mm AM/PM')
Valid choices for different displays of AM/PM values are:
AM/PM 值不同显示的有效选择是:
AM/PM
Use the 12-hour clock and display an uppercase AM with any hour before noon; display an uppercase PM with any hour between noon and 11:59 P.M.
am/pm
Use the 12-hour clock and display a lowercase AM with any hour before noon; display a lowercase PM with any hour between noon and 11:59 P.M.
A/P
Use the 12-hour clock and display an uppercase A with any hour before noon; display an uppercase P with any hour between noon and 11:59 P.M.
a/p
Use the 12-hour clock and display a lowercase A with any hour before noon; display a lowercase P with any hour between noon and 11:59 P.M.
AMPMUse the 12-hour clock and display the AM string literal as defined by your system with any hour before noon; display the PM string literal as defined by your system with any hour between noon and 11:59 P.M. AMPM can be either uppercase or lowercase, but the case of the string displayed matches the string as defined by your system settings. The default format is AM/PM.
上午下午
使用 12 小时制,并在中午之前的任何小时显示大写的 AM;在中午和晚上 11:59 之间的任何时间显示大写 PM
上午下午
使用 12 小时制,并在中午之前的任何小时显示小写的 AM;在中午和晚上 11:59 之间的任何时间显示小写的 PM
应付帐款
使用 12 小时制,并在中午之前的任何小时显示一个大写的 A;在中午和晚上 11:59 之间的任何时间显示一个大写的 P
一/一
使用 12 小时制,并在中午之前的任何小时显示小写字母 A;在中午和晚上 11:59 之间的任何时间显示小写 P
AMPM使用 12 小时制并在中午之前的任何小时显示系统定义的 AM 字符串文字;在中午和晚上 11:59 之间的任何时间显示系统定义的 PM 字符串文字 AMPM 可以是大写或小写,但显示的字符串的大小写与系统设置定义的字符串相匹配。默认格式为 AM/PM。