The estate Now do C# brings the current date and time, different from JS Now.
The estate Millisecond returns an integer equivalent to milliseconds from the time Now was evaluated. It is clearer with the example below:
Console.WriteLine("Data com millisegundos: {0:MM/dd/yyy HH:mm:ss.fff}, {1}",
DateTime.Now,DateTime.Now.Millisecond);
To create the same behavior in C# you should do so:
using System;
public class Program
{
public static void Main()
{
DateTime d1 = new DateTime(1970, 1, 1);
DateTime d2 = DateTime.Now;
double x = new TimeSpan(d2.Ticks - d1.Ticks).TotalMilliseconds;
double y =((DateTimeOffset)DateTime.UtcNow).ToUnixTimeMilliseconds();
Console.WriteLine("Calculo com Ticks {0}",x);
Console.WriteLine("Calculo com UtcNow {0}",y);
}
}
Note that the Ticks method has a slightly higher resolution than the Utcnow method.
See working on .NET Fiddle
This code has returned since 1 January 1970 00:00:00 ?
– Matheus Miranda
Yes, same as JS. What can be checked in the links I posted.
– Maniero
Wow didn’t know that:
ToUnixTimeSeconds()
.– Matheus Miranda
@Matheusmiranda I was wrong,
ToUnixTimeMilliseconds
already makes all the adjustment, read enough things, and both using . utcNow and . now the result will be the same forToUnixTimeMilliseconds
, because probably the class internally already knows the Timezone that the server operates, so disregard my other comment.– Guilherme Nascimento