【问题标题】:This code snippet isn't working as expected (VBScript)此代码段未按预期工作(VBScript)
【发布时间】:2011-10-28 21:36:25
【问题描述】:
        Dim value
        value = CDate(InputBox("Please enter the time (hh:mm)", "Time Input", FormatDateTime(Now, 4)))          
        ' validate the input here
        WScript.Echo value
        internal_Time = CDate(FormatDateTime(value, 4))

我预计时间为 08:24 或 13:12,但现在显示为上午 8:26:12

【问题讨论】:

    标签: scripting vbscript


    【解决方案1】:

    这里:

    internal_Time = CDate(FormatDateTime(value, 4))
    

    您的格式为 string,但随后又转换回 Date,因此格式丢失,值被转换为包含 AM/PM 的 VB 日期值,如果它用于显示,则只需存储字符串:

    internal_Time = FormatDateTime(value, 4)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-05
      • 2020-11-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多