How to convert current time to timestamp in seconds

I want the current time in the format of timestamp in seconds.
eg: 16:24:38 should be converted to 1524480878.
using Now.toLongtimestring I can get the value in HH:MM:SS. Need help to convert it to timestamp in seconds.

Hello @sadhana,

Please use below statement,
Now.ToString(“hhmmss”);

Thanks,
Pankaj

it gives the output in hhmmss. I want in timestamp format like 1524480878.

hey @sadhana

You can try Like below:

Double Timestamp_in_Seconds=DateTime.Now.ToUniversalTime() - new DateTime (1970, 1, 1)).TotalSeconds;

So if you want non floating seconds then use Convert.ToInt32.

For your Reference - Current Time To TImestamp To Seconds.xaml (4.6 KB)

Regards…!!
Aksh

1 Like

Hey @aksh1yadav

Your code helped me, thanks for posting this.

Regards,
Vamsi

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.