How to convert current time to timestamp in seconds

studio

#1

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.


#2

Hello @sadhana,

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

Thanks,
Pankaj


#3

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


#4

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