gpt4 book ai didi

vba - 获取日期模式 yyyy-MM-dd HH :mm:ss z with VBA

转载 作者:行者123 更新时间:2023-12-02 19:26:06 25 4
gpt4 key购买 nike

我正在尝试使用 VBA 获取此日期模式 yyyy-MM-dd HH:mm:ss z 但找不到任何解决方案。

我从 Excel 单元格或 Now 函数获取输入时间,然后使用 Format 函数对其进行格式化,但没有找到任何可以提供时区信息的格式。

Format(Now, "yyyy-dd-MM HH:mm:ss")

感谢您的帮助!

最佳答案

Excel 中的日期/时间字段不包含任何时区信息。其数字表示形式是“OLE 自动化日期”,其中 according to MSDN定义为:

An OLE Automation date is implemented as a floating-point number whose integral component is the number of days before or after midnight, 30 December 1899, and whose fractional component represents the time on that day divided by 24. For example, midnight, 31 December 1899 is represented by 1.0; 6 A.M., 1 January 1900 is represented by 2.25; midnight, 29 December 1899 is represented by -1.0; and 6 A.M., 29 December 1899 is represented by -1.25.

此定义中没有任何地方说明时区引用是什么。它不一定是您查看文件的计算机的本地时区,因为您可以将文件移动到另一个时区的计算机,并且数据不会更改。它也不一定基于 UTC。至少,没有任何内容明确将数据定义为 UTC。您也可以将本地日期/时间值显示为具有相同表示形式的 UTC 日期/时间值。

因此,只有您作为 Excel 电子表格的所有者才能确定给定日期/时间字段中的数据对于时区的含义。如果您知道字段包含 UTC 时间戳,则只需在输出字符串中添加字符 Z 即可。如果您知道字段固定为 UTC+2,请将 +02:00 添加到输出字符串。如果您只知道这些字段采用“太平洋时间”,那么您就会遇到问题,因为您必须确定它们是采用 PST (-08:00) 还是 PDT (-07:00)。您可以为此使用公式或外部函数,但没有内置任何内容,也没有任何信息可以告诉您该字段完全采用太平洋时间 - 除了您自己的外部知识之外。

关于vba - 获取日期模式 yyyy-MM-dd HH :mm:ss z with VBA,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39570388/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com