How can I generate Unix timestamps?
In Linux or MacOS you can use: date +%s where +%s, seconds since 1970-01-01 00:00:00 UTC. (GNU Coreutils 8.24 Date manual) Example output now 1454000043.
In Linux or MacOS you can use: date +%s where +%s, seconds since 1970-01-01 00:00:00 UTC. (GNU Coreutils 8.24 Date manual) Example output now 1454000043.
On systems with GNU Coreutils >= 5.3.0, e.g. Linux you can use: date -d @1267619929
As of .NET 4.6, there is DateTimeOffset.ToUnixTimeSeconds. This is an instance method, so you are expected to call it on an instance of DateTimeOffset. You can also cast any instance of DateTime, though beware the timezone. To get the current timestamp: DateTimeOffset.Now.ToUnixTimeSeconds() To get the timestamp from a DateTime: DateTime foo = DateTime.Now; long unixTime … Read more
Use datetime module: from datetime import datetime ts = int(‘1284101485’) # if you encounter a “year is out of range” error the timestamp # may be in milliseconds, try `ts /= 1000` in that case print(datetime.utcfromtimestamp(ts).strftime(‘%Y-%m-%d %H:%M:%S’))