繁体   English   中英

Excel 时间格式 2019-01-20T08:00:00-02:00(或 ccyy-mm-yyThh:mm:ss-timezone)

[英]Excel time format 2019-01-20T08:00:00-02:00 (or ccyy-mm-yyThh:mm:ss-timezone)

我需要在 Excel 上使用 ISO8601 日期时间格式。示例 2019-01-20T08:00:00-02:00(或 ccyy-mm-yyThh:mm:ss-timezone)。 假设我在单元格 A1 中使用它。 在单元格 B1 中,我想添加 1 天 8 小时,是否有我可以使用的公式? (即:我希望单元格 B1 中的日期和时间为 2019-01-21T16:00:00-02:00

我需要在 Excel 上使用 ISO8601 日期时间格式。示例 2019-01-20T08:00:00-02:00(或 ccyy-mm-yyThh:mm:ss-timezone)。 假设我在单元格 A1 中使用它。 在单元格 B1 中,我想添加 1 天 8 小时,是否有我可以使用的公式? (即:我希望单元格 B1 中的日期和时间为 2019-01-21T16:00:00-02:00

一个简单的解决方案是将这个 function 放在模块中,并从任何单元格调用,如“=GetFullUTC(D12)”或“=GetFullUTC()”

    Public Function GetFullUTC(Optional d As Variant) As String
    
    Dim dt As Object
    Dim tStr As String
    Set dt = CreateObject("WbemScripting.SWbemDateTime")
    If IsDate(d) Then
       dt.SetVarDate d
     Else
     dt.SetVarDate Now
    End If
    tStr = dt.Value
    GetFullUTC = Left(tStr, 4) & "-" & Mid(tStr, 5, 2) & "-" & Mid(tStr, 7, 2) & "T" & Mid(tStr, 9, 2) & ":" & Mid(tStr, 11, 2) & ":" & Mid(tStr, 13, 2) & Mid(tStr, 15, 4) & Mid(tStr, 22, 1) & Format(Abs(Mid(tStr, 23, 3) / 60), "00") & ":00"
    End Function

请记住,function 返回的是字符串而不是日期。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM