Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML input type date and time without timezone offset

I am using HTML5 input date and input time for ionic development. By default, it binds as ISO Date String and change to UTC date time. It seems wrong to me as when user choose the date 2016-06-06, it may have become 2016-06-07 or 2016-06-05 depending on timezone offset. Similar situation for input type = time.

What my intention is to make the Date in ISO String to remain of what user chosen instead of offset it with timezone difference.

Something like input datetime-local but seems that datetime-local is not supported by mobile device.

I am finding something like input type="date-local" or "time-local".

like image 340
eulercode Avatar asked Apr 07 '16 20:04

eulercode


People also ask

How do you make a date without time zones?

To create a date without timezone:Get the ISO representation of the date string. Remove the Z character from the end of the ISO string. Pass the result to the Date() constructor.

Which input type is used for display only date and time?

The <input type="datetime-local"> defines a date picker. The resulting value includes the year, month, day, and time.

How can set date format in input Type date in HTML?

To set and get the input type date in dd-mm-yyyy format we will use <input> type attribute. The <input> type attribute is used to define a date picker or control field. In this attribute, you can set the range from which day-month-year to which day-month-year date can be selected from.

How do I show date and time in HTML?

The <time> datetime Attribute in HTML is used to defines the machine-readable date/time of the <time> element. The date-time is inserted in the format YYYY-MM-DDThh:mm:ssTZD.


1 Answers

First of all it is interesting that type="datetime" has been removed from the HTML5 standard and instead only "datetime-local" exists, yet it appears that not every mobile browser implements it. For type="date", it doesn't have a time component, so just use the UTC date directly. True, converting a UTC date d to local is kind of ridiculous:

  • new Date(d.toLocaleDateString())

or

  • d.setMinutes(d.getMinutes()+d.getTimezoneOffset())

or

  • new Date(+d+d.getTimezoneOffset()*60000)

but what can you do?

like image 194
Siderite Zackwehdex Avatar answered Oct 20 '22 15:10

Siderite Zackwehdex