How can I generate Unix timestamps?

2019-01-29 20:10发布

Related question is "Datetime To Unix timestamp", but this question is more general.

I need Unix timestamps to solve my last question. My interests are Python, Ruby and Haskell, but other approaches are welcome.

What is the easiest way to generate Unix timestamps?

15条回答
Ridiculous、
2楼-- · 2019-01-29 20:30

curl icanhazepoch.com

Basically it's unix timestamps as a service (UTaaS)

查看更多
Summer. ? 凉城
3楼-- · 2019-01-29 20:33

In python add the following lines to get a time stamp:

>>> import time
>>> time.time()
1335906993.995389
>>> int(time.time())
1335906993
查看更多
三岁会撩人
4楼-- · 2019-01-29 20:35
public static Int32 GetTimeStamp()
    {
        try
        {
            Int32 unixTimeStamp;
            DateTime currentTime = DateTime.Now;
            DateTime zuluTime = currentTime.ToUniversalTime();
            DateTime unixEpoch = new DateTime(1970, 1, 1);
            unixTimeStamp = (Int32)(zuluTime.Subtract(unixEpoch)).TotalSeconds;
            return unixTimeStamp;
        }
        catch (Exception ex)
        {
            Debug.WriteLine(ex);
            return 0;
        }
    }
查看更多
爷、活的狠高调
5楼-- · 2019-01-29 20:37

For completeness, PHP:

php -r 'echo time();'

In BASH:

clitime=$(php -r 'echo time();')
echo $clitime
查看更多
爷的心禁止访问
6楼-- · 2019-01-29 20:38

In Haskell...

To get it back as a POSIXTime type:

import Data.Time.Clock.POSIX
getPOSIXTime

As an integer:

import Data.Time.Clock.POSIX
round `fmap` getPOSIXTime
查看更多
干净又极端
7楼-- · 2019-01-29 20:40

in Ruby:

>> Time.now.to_i
=> 1248933648
查看更多
登录 后发表回答