2

Is there any equivalent of Javascript new Date().valueOf() in C#?

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

I need this because, I'm writing some serverless aws lambda code where they are supporting both nodeJs and C# code.

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

In future, I may query on the datetime values.

RealSteel
  • 1,871
  • 3
  • 37
  • 74

1 Answers1

5

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

DateTime startDt = new DateTime(1970, 1, 1);
TimeSpan timeSpan = DateTime.UtcNow - startDt;
long millis = (long)timeSpan.TotalMilliseconds;
Tim Schmelter
  • 450,073
  • 74
  • 686
  • 939