angular-datepicker icon indicating copy to clipboard operation
angular-datepicker copied to clipboard

How to get date in UTC?

Open iamstormnet opened this issue 8 years ago • 8 comments

Hi, currently the datepicker is using my browsers tz, but i want to have it ALWAYS to use utc regardless where the user sits in the world. How can i achieve this?

iamstormnet avatar Dec 17 '16 21:12 iamstormnet

Use the timezone UTC.

For example, <div date-picker timezone="UTC"></div>

DanTalash avatar Jan 03 '17 03:01 DanTalash

@DanTalash Didn't work for me.. <div date-picker timezone="UTC"></div>

leonardors95 avatar Feb 21 '17 16:02 leonardors95

It appears to work for me on Chrome/Firefox/IE. Does this plunkr work for you?

DanTalash avatar Feb 21 '17 17:02 DanTalash

Yeah it seems normal, but I tried something like the Live demo and it does not work .. do you have some tips, what i'm doing wrong? Example: <input date-time ng-model="dates.minDate" id="pickerMinSelector" date-change="changeMinMax" max-date="maxDate" view="date" timezone="UTC" format="lll" class="ng-pristine ng-valid ng-scope ng-valid-max ng-touched">

Thanks.

leonardors95 avatar Feb 21 '17 17:02 leonardors95

I still cannot reproduce any issue. Please see this updated plunkr. Does it appear normal to you?

DanTalash avatar Feb 21 '17 20:02 DanTalash

I expected this format: DD/MM/YYYY HH:mm 22/02/2017 08:45, but is showing like this :2017-02-18T12:00:00.000Z.(Look the date.minDate format) Example: <input date-time ng-model="dates.minDate" date-change="changeMinMax" max-date="maxDate" view="date" timezone="UTC" format="DD/MM/YYYY HH:mm"> {{dates.minDate}}

leonardors95 avatar Feb 22 '17 12:02 leonardors95

You should look into the moment format functions. Because dates.minDate is a moment object, if you need to display it in a particular format then you will need to specify what the format is. If you just dump it to the page with the curly braces, angular calls toString() on the object, which is why you're seeing the unexpected date format.

Look at this updated plunkr for an illustration.

DanTalash avatar Feb 22 '17 14:02 DanTalash

@DanTalash Thanks for the help, it solved my problem :+1:

leonardors95 avatar Feb 22 '17 18:02 leonardors95