Before we move on, I want to mention a few things about datetime-local. Firstly, <input type="datetime-local"> represents a field for a local date and time without time-zone information.

This just means that the users local time will be sent to the server (in other words, the date will not be converted to UTC).


When may this be useful?


Well, this type of field is particularly useful for gathering a point in time, that is specific to a location. For example, it could be used in a form to set or change the date and time of a birthday party, celebrated at a specific location, as the participants would have to be in the place in order to attend.


datetime has been deprecated


In order to avoid awkward and confusing user experience due time zones, the input type datetime has been removed from HTML specifications: we’re left with datetime-local, where supported.


Datetime-local is user timezone based


In other words, the input value is not a UTC one.

You can, however, save it as ISO string by using the toISOString() method, which will return a date in the ISO 8601 format according to universal time.

Example: new Date(input.value).toISOString();


Where did datetime-local come from?


The datetime-local value was not introduced in HTML5, but at the time of writing, it has been introduced in the HTML 5.1 draft, as well as the WHATWG HTML Living Standard.


What about validation? 


By default, <input type="datetime-local"> does not apply any validation to entered values. The UI implementations generally don't let you enter anything that isn't a date/time — which is helpful — but a user is allowed to fill in no value and submit, or enter an invalid date and/or time (e.g. the 35th of June).


What if Coordinated Universal Time is important to you?


Coordinated Universal Time (or UTC) is recommended for use in applications that require dates and times to be stored or represented in a time zone agnostic fashion. If this is important to you, use the <input type="date"> instead.


That's all I wanted to say about datetime-local.

Smile, have fun, and see you in the next lecture :)