Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get Unix / Epoch time as Int

Tags:

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?

like image 894
jajdoo Avatar asked Jul 28 '13 15:07

jajdoo


People also ask

How do I get epoch time in Unix?

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.

Is Unix timestamp an integer?

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.

How do you convert epoch time to human readable?

Bookmark this question. Show activity on this post. To convert epoch dateTime to human readable , using a simple new date(1495159447834) will suffice.

Is epoch time in UTC?

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.


2 Answers

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 
like image 200
ДМИТРИЙ МАЛИКОВ Avatar answered Sep 30 '22 07:09

ДМИТРИЙ МАЛИКОВ


Try this:

import Data.Time import Data.Time.Clock.POSIX  t = getPOSIXTime 

It has 6 decimal places of accuracy.

like image 24
Blue Ice Avatar answered Sep 30 '22 06:09

Blue Ice