question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

DateTime transforms ISO time string without timezone into UTC

See original GitHub issue

Short description of the problem:

When I use an <ion-datetime> and set the initial value to an ISO time string without a timezone (e.g. 2016-07-03T15:30), after changing the time the string now has a ‘Z’ at the end signifying UTC.

What behavior are you expecting?

It says in the Ionic docs:

Any of the ISO formats below can be used, and after a user selects a new value, Ionic will continue to use the same ISO format which datetime value was originally given as. … Date and Time | YYYY-MM-DDTHH:mm | 1994-12-15T13:47

I would expect, then, for my format (YYYY-MM-DDTHH:mm) to remain the same. Sorry if I have misunderstood this. If my issue is expected behavior, then I guess the docs should be updated.

Steps to reproduce:

  1. Initialize an <ion-datetime> with an ISO string without a timezone specified.
  2. Change the date using the picker.

Which Ionic Version?

2.x

Plunker that shows an example of your issue

http://plnkr.co/edit/w0aio9JY1osYKzOJaqtd?p=preview

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
shyamal890commented, Feb 17, 2017

Mike, suggests that Ionic wouldn’t be handling this issue. Reference

Humbly tagging @adamdbradley @danbucholtz @mlynch to please have a relook at this issue.

1reaction
mhartingtoncommented, Feb 17, 2017

So there’s no good cross-platform way to handle this. Each browser would do something different and it is very error prone.

A better way would be to use ngModel and a pipe

<ion-datetime 
  displayFormat="hh:mm A" 
  [ngModel]="firstDate | formatToLocal" 
  (ngModelChange)="firstDate=$event">
</ion-datetime>

This will let you pass the value to something like momentJS or Date-fns as a pipe then update the value on change as well

http://plnkr.co/edit/MHjUdC

Read more comments on GitHub >

github_iconTop Results From Across the Web

DateTime transforms ISO time string without timezone into UTC
Steps to reproduce: Initialize an <ion-datetime> with an ISO string without a timezone specified. Change the date using the picker.
Read more >
Safari is parsing ISO 8601 date-time strings without timezone ...
In Safari these time strings are interpreted as UTC and then the string format converts it to local time. new Date("2020-05-06T13:25:00").
Read more >
Create a Date without Timezone using JavaScript | bobbyhadz
To create a date without timezone, get the ISO representation of the date string. ... my time zone is 3 hours ahead of...
Read more >
Convert ISO UTC date.time to Local timezone - ServiceNow
Solved: i have an ISO date 2020-09-15T04:52:16.833Z in a Script step in Action Designer, how can apply the system timezone to the value...
Read more >
Demystifying DateTime Manipulation in JavaScript - Toptal
We will ignore the user's time zone and use UTC while creating the date object. There are two ways to do it: Create...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found