{

Nim example - epoch unix timestamp, Local and Utc datetime


This tutorial explains multiple ways to get Datetime in Local and UTC as well as EPOCH timestamp.

How to get the Current Epoch unix timestamp in NIm.

times module hasepochTime() proc that returns a number of milliseconds since the 1970 date. It returns a floating number.

import std/[times]

let currentTimestamp = epochTime()
echo currentTimestamp

Output

1682999883.740629

How to get Current DateTime in Local and UTC NIm.

now() in the times module returns the current DateTime in Local time.

now().utc in the times module returns the current UTC date and time

Here is an example

import std/[times]

let now1 = now()   
let now2 = now().utc

echo now1
echo now2
echo currentTimestamp

Output

2023-05-02T03:58:03+00:00
2023-05-02T03:58:03Z
1682999883.740629
THE BEST NEWSLETTER ANYWHERE
Join 6,000 subscribers and get a daily digest of full stack tutorials delivered to your inbox directly.No spam ever. Unsubscribe any time.

Similar Posts
Subscribe
You'll get a notification every time a post gets published here.