Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you get a millisecond-precision unix timestamp in Haskell?

What is the Haskell equivalent of this shell command?

$ date "+%s%3N"
1489694389603
like image 724
Chris Martin Avatar asked Mar 16 '17 20:03

Chris Martin


People also ask

Does Unix timestamp have milliseconds?

Datetime Unix timestamp contains milliseconds.

Are timestamps in milliseconds?

Timestamps in milliseconds and other units. Timezones, Unix timestamps in milliseconds & UTC.

How do you get time in Haskell?

You can use getCurrentTime from Data. Time. Clock . Save this answer.


1 Answers

Using the time package:

  1. Use getPOSIXTime, which returns a NominalDiffTime. This represents a fractional number of seconds, with a precision of 10-12 seconds.

  2. Multiply 1000 to convert from seconds to milliseconds.

  3. NominalDiffTime implements the RealFrac class, so you can use round to convert to an integer.


import Data.Time.Clock.POSIX (getPOSIXTime)

λ> (round . (* 1000)) <$> getPOSIXTime
1489694668011
like image 110
Chris Martin Avatar answered Sep 28 '22 05:09

Chris Martin