My server returns date data as local timezone timestamps.
On the client-side, I want to display those dates as local date strings. If I do the following, I got the wrong date ("6/30/2014" instead of "7/01/2014")
var ts = 1404172800;
new Date(1404172800*1000).toLocaleDateString()
>>>"6/30/2014"
To prevent this problem, I suppose I have to convert the local timezone timestramp I receive from the server to UTC timestamp before creating the new Date()
object.
Am I right? What is the best way to achieve that that will work in most browsers?
Edit:
I confirm that the real date in local time zone should be 7/01/2014. That's local Eastern time UTC -5(-4). but the new Date()
object thinks this is UTC but it's not. I suppose it's because the date is returned as a timestamp without having been converted to UTC.