1

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,817
  • 3
  • 34
  • 65

1 Answers1

4

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
  • 429,027
  • 67
  • 649
  • 891