1

in fact, I called my java services from AngularJS and I go back an object that contains a date, for example:

{
"Name": "Jhon"
"date": 1465826400000
}

in my service java 1465826400000 date corresponds to Monday, June 13, 2016 14: 00 UTC and in my Javascript code:

var date = new Date (1465826400000);

and it gives 14-06-2016 4:00:00

that means one day lag between the two dates.

someone has an idea

0

1 Answer 1

4

No, it just means you're looking at the result in the local timezone of your browser. If you look at it as a UTC date, it matches:

console.log(new Date (1465826400000).toISOString()); // "2016-06-13T14:00:00.000Z"

Sign up to request clarification or add additional context in comments.

2 Comments

thank you Crowder, it means that at my service java I have to convert the date to utc ?
@Cheps: It depends entirley on where that number came from. If you're going to use numbers (rather than human-readable strings), your best bet is probably milliseconds-since-The-Epoch (what you get from Java's Date.getTime). Those aren't sensitive to timezones. When you use JavaScripts' new Date(number), it will represent that exact same date/time. JavaScript's Date object has methods that you can use to get the parts of that date (or a string) converted to local time, and ones for UTC. Just use what you need.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.