【问题标题】:Find Date Difference in BrightScript在 BrightScript 中查找日期差异
【发布时间】:2021-08-28 14:00:50
【问题描述】:

我对日期时间有疑问。

我有两个字符串。 例如24-9-152-10-15。 两者都是两个字符串。

我想找出它们之间的差异(以天为单位)。

你能帮帮我吗?

【问题讨论】:

    标签: roku brightscript


    【解决方案1】:

    1) 将 2 个字符串解析为 roDateTime 对象。

    参考 - http://sdkdocs.roku.com/display/sdkdoc/roDateTime

    2) 通过 date1.AsSeconds()date2.AsSeconds() 获取两个日期的时间(以秒为单位)

    3) 减去 2 次,所以你有以秒为单位的时间差。

    4) 将此秒除以 3600 转换为小时,然后除以 24 转换为天

    即。 (seconds/3600) / 24

    【讨论】:

    • 非常感谢。我会试试这个。
    • @akshat 您能否在答案中提供完整的代码示例。这将是有帮助的,而不是一个链接。
    【解决方案2】:
    date1 = CreateObject("roDateTime")
    date2 = CreateObject("roDateTime")
    diffInSeconds = date1.asSeconds() - date2.asSeconds()
    print "seconds lapsed " diffInSeconds
    

    【讨论】:

    • 你的方法很好。但是,如何解析日期中的日期和时间字符串值?
    【解决方案3】:

    如果这些是您的字符串,我认为没有任何功能可以帮助您。您可能必须手动执行此操作。不过,您可以查看ifDateTime 函数,看看它们是否有帮助。

    【讨论】:

      【解决方案4】:
      Function GetDurationString(totalSeconds = 0 As Integer) As String
      remaining = totalSeconds
      hours = Int(remaining / 3600).ToStr()
      remaining = remaining Mod 3600
      minutes = Int(remaining / 60).ToStr()
      remaining = remaining Mod 60
      seconds = remaining.ToStr()
      
      If hours <> "0" Then
          Return PadLeft(hours, "0", 2) + "hours " + PadLeft(minutes, "0", 2) + "minutes " + PadLeft(seconds, "0", 2) +" seconds"
      Else
          Return PadLeft(minutes, "0", 2) + "minutes " + PadLeft(seconds, "0", 2)+" seconds"
      End If
      End Function
      

      ================================================ ========================

      Function PadLeft(value As String, padChar As String, totalLength As Integer) As String
      While value.Len() < totalLength
          value = padChar + value
      End While
      Return value
      End Function
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-11-17
        • 1970-01-01
        • 2019-07-27
        相关资源
        最近更新 更多