I’m using .NET to generate a JSON file that has many Dates in it.
For compression, I want to store them as milliseconds since Jan 1, 1970 and not strings, then convert them to Javascript Dates. But .Net’s idea of milliseconds since 1970-01-01 don’t match Javascript:
Javascript:
Date.parse("2012-05-15T13:57:57.0000000+00:00")
1337090277000
VB.Net:
Date.Parse("2012-05-15T13:57:57.0000000+00:00").Subtract(New Date(1970,1,1)).TotalMilliseconds
1337101077000.0
The difference is 10800 seconds. The difference at 1970-01-01 is 0 and changes over time.
Is there a way to compute Javascript’s idea of milliseconds-since-epoch from within .Net?
You are comparing apples to oranges.
This is exactly what you would get in javascript as well when in UTC+3 (Israel):
This is because when you do
new Datein javascript, that’s according to the machine’s timezone. It looks like it’s the same for vb.net.You would get the correct number in javascript with:
In VB.net