I've got a year, month, day, hour and minute value (all of them are of type Int
) - how can I convert these to a UTCTime
or UniversalTime
?
Asked
Active
Viewed 247 times
2

Chris Stryczynski
- 30,145
- 48
- 175
- 286
1 Answers
3
The following imports are required:
import Control.Lens
import Data.Thyme.Clock
import Data.Thyme.Calendar
And then:
makeUtcTime :: Year -> Month -> DayOfMonth -> Int -> UTCTime
makeUtcTime y m d x = UTCTime ((YearMonthDay y m d)^.from gregorian) (toEnum x) ^. from utcTime
Within ghci:
:t makeUtcTime 2020 1 1 9143892431
makeUtcTime 2020 1 1 9143892431 :: UTCTime
(Perhaps there's a simpler way, but this is not too bad)

Chris Stryczynski
- 30,145
- 48
- 175
- 286

chi
- 111,837
- 3
- 133
- 218
-
This actually seems to give a type of `UTCView` `:t UTCTime ((YearMonthDay 2018 7 21)^.from gregorian) (toEnum 0)UTCTime ((YearMonthDay 2018 7 21)^.from gregorian) (toEnum 0) :: UTCView`. – Chris Stryczynski Jan 04 '20 at 17:30