Is there a function in haskell for epoch time in seconds / milliseconds ?
perhaps something similar to java's
System.currentTimeMillis();
edit: as Int
or Integer
?
Convert from human-readable date to epochlong epoch = new java.text.SimpleDateFormat("MM/dd/yyyy HH:mm:ss").parse("01/01/1970 01:00:00").getTime() / 1000; Timestamp in seconds, remove '/1000' for milliseconds. date +%s -d"Jan 1, 1980 00:00:01" Replace '-d' with '-ud' to input in GMT/UTC time.
Because the Unix timestamp uses an unsigned 32-bit integer, it does have a maximum of time that can be counted before the number “rolls over” into a negative number. Based on current Unix time, the rollover time will be 03:14:07 UTC on 19 January 2038.
Bookmark this question. Show activity on this post. To convert epoch dateTime to human readable , using a simple new date(1495159447834) will suffice.
In a computing context, an epoch is the date and time relative to which a computer's clock and timestamp values are determined. The epoch traditionally corresponds to 0 hours, 0 minutes, and 0 seconds (00:00:00) Coordinated Universal Time (UTC) on a specific date, which varies from system to system.
Yes.
getCurrentTime :: IO UTCTime
.
UNIX epoch time could be retrieved as Int
like that:
> :m + Data.Time System.Locale Control.Applicative > epoch_int <- (read <$> formatTime defaultTimeLocale "%s" <$> getCurrentTime) :: IO Int > epoch_int 1375025861
UPD: as other users noticed, there is much more simple way to do that:
> :m + Data.Time.Clock.POSIX > round `fmap` getPOSIXTime 1375040716 it :: Integer
Try this:
import Data.Time import Data.Time.Clock.POSIX t = getPOSIXTime
It has 6 decimal places of accuracy.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With