RealSteel RealSteel -3 years ago 202
Javascript Question

Javascript Date valueOf equivalent in C#

Is there any equivalent of Javascript

new Date().valueOf()
in C#?

I tried using
in c#, but both are different.

I need this because, I'm writing some
serverless aws lambda code
where there they are supporting both

So, I don't want to get any conflict with datetime in future.

In future, I may query on the datetime values.

Answer Source

new Date().valueOf returns the milliseconds since january 1, 1970, you can use this C# code:

DateTime startDt = new DateTime(1970, 1, 1);
TimeSpan timeSpan = DateTime.Now - startDt;
long millis = (long)timeSpan.TotalMilliseconds;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download