How can I replicate this in javascript?
Now.Ticks.ToString
There is no real equivalent. You ask two questions:
How do I get the current date & time in javascript? This is easy, just write
var now = new Date();
How do I get the number of ticks since Januari 1, 0001? This one is harder, because javascript doesn't work with ticks, but with milliseconds, and the offset is Januari 1, 1970 instead.
You can start with now.getTime()
to get the milliseconds since Jan 1, 1970, and then multiply this with 10000. I just calculated the number of ticks between 0001-01-01 and 1970-01-01, and this is 621355968000000000. If you also take into account the timezone, the resulting code looks like this:
function getTicks(date)
{
return ((date.getTime() - date.getTimezoneOffset() * 60000) * 10000) + 621355968000000000;
}
Now getTicks(new Date())
will get the same result as Now.Ticks.ToString
in VB.Net with an error margin of 1 millisecond.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With