【问题标题】:Yesod Persistent - How to compare Day to UTCTime? (How to convert them?)Yesod Persistent - 如何将 Day 与 UTCTime 进行比较? (如何转换它们?)
【发布时间】:2016-04-30 21:40:09
【问题描述】:

我有一个UTCTime 类型的值表示当前时间,还有一个Day 类型的值我想知道它是否大于或等于当前时间。

【问题讨论】:

    标签: haskell yesod persistent


    【解决方案1】:

    UTCTimeDay (utctDay) 和自午夜以来的秒数 (utctDayTime) 组成。这是一个 GHCi 会话,展示了如何访问这一天:

    ghci > import Data.Time
    ghci > time <- getCurrentTime
    ghci > :t time
    time :: UTCTime
    ghci > utctDay time
    2016-04-30
    ghci > :t utctDay time
    utctDay time :: Day
    

    一旦您可以访问Day,您就可以使用标准比较函数(&gt;&gt;===&lt;&lt;=):

    ghci > t1 <- getCurrentTime
    ghci > t2 <- getCurrentTime
    ghci > t1
    2016-04-30 21:59:06.808488 UTC
    ghci > t2
    2016-04-30 21:59:11.920389 UTC
    ghci > (utctDay t1) >= (utctDay t2)
    True
    

    您可能还想查看the Haddocks for UTCTime

    【讨论】:

      猜你喜欢
      • 2020-04-18
      • 2019-02-19
      • 1970-01-01
      • 1970-01-01
      • 2023-03-30
      • 2020-09-17
      • 2017-05-10
      • 1970-01-01
      • 2013-04-05
      相关资源
      最近更新 更多