W3cubDocs

/Haskell 8

Data.Time.Clock.POSIX

Safe Haskell Safe
Language Haskell2010

Description

POSIX time, if you need to deal with timestamps and the like. Most people won't need this module.

You can use POSIXTime to obtain integer/word timestamps. For example:

import Data.Time
import Data.Time.Clock.POSIX
import Data.Int

nanosSinceEpoch :: UTCTime -> Int64
nanosSinceEpoch =
    floor . (1e9 *) . nominalDiffTimeToSeconds . utcTimeToPOSIXSeconds

main :: IO ()
main = do
    u <- getCurrentTime
    print $ nanosSinceEpoch u

posixDayLength :: NominalDiffTime Source

86400 nominal seconds in every day

type POSIXTime = NominalDiffTime Source

POSIX time is the nominal time since 1970-01-01 00:00 UTC

To convert from a CTime or System.Posix.EpochTime, use realToFrac.

posixSecondsToUTCTime :: POSIXTime -> UTCTime Source

utcTimeToPOSIXSeconds :: UTCTime -> POSIXTime Source

getPOSIXTime :: IO POSIXTime Source

Get the current POSIX time from the system clock.

getCurrentTime :: IO UTCTime Source

Get the current UTCTime from the system clock.

systemToPOSIXTime :: SystemTime -> POSIXTime Source

© The University of Glasgow and others
Licensed under a BSD-style license (see top of the page).
https://downloads.haskell.org/~ghc/8.8.3/docs/html/libraries/time-1.9.3/Data-Time-Clock-POSIX.html