0

I'm going crazy with this simple stuff:

$scope.targetData=new Date("09 21 2015 18:04:00");
$scope.clock = new Date();

This render : targetData="2015-09-21T16:04:00.000Z" and clock="2015-09-21T16:36:53.314Z"

but in Italy it is 18:04:00... so how can I set correct ?? Thanks..

4
  • The 'Z' at the end means "in the UTC time zone". Italy is at UTC+2 at that date. So "09 21 2015 18:04:00" in Italy is indeed equal to "2015-09-21T16:04" in UTC. Use the date filter to render the date the way you want, in the browser timezone. Commented Sep 21, 2015 at 16:44
  • 1
    Also note that you're getting that as the output of toString() implicitly being called on the Date object. The behavior of that is implementation dependent. On Firefox, you will see the UTC time in ISO format, but in other browsers you may see the local time in RFC2822 format, or in some other locale-centric format. Commented Sep 21, 2015 at 17:24
  • Also also note that javascript's clock will be based on the user's local time, not yours (or the server's.) So be wary of doing any timezone conversion based on e.g. getTimezoneOffset, or you'll get unpredictable results unless every one of your users is in the same timezone. It's almost always best to do everything in UTC and then only convert to local time before display. Commented Sep 21, 2015 at 17:31
  • thanks to every one.. valuable advice! Commented Sep 21, 2015 at 17:59

2 Answers 2

1

If you are willing to use dependencies, an extermely easy and well-used solution for almost all Date related usages and problems, moment.js can be your friend:

http://momentjs.com/
http://momentjs.com/timezone/

Angular-Ported: https://github.com/urish/angular-moment

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

Comments

0

First of all, it has nothing to do with AngularJS. Date is JavaScript object.

I would say, that it simply converts input time to your local time. And you're saying, that the input time is in UTC. Try to add your timezone explicitly. That means instead of "Z" (means +0000 which is UTC) as a timezone, use your timezone or just try to omit timezone completely, I guess it will expect input time is in your local time.

See Date documentation for details and date time format.

2 Comments

ok my error, it is a javascript question. how can I set correctly tie zone?
You have everything you need in that documentation. Date and time format specifically is described in the Internet Message Format RFC.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.