4

I am trying to create a simple HTML form and the one element must capture the date and time, I am currently using:

 <input type="datetime-local" id="early" name="early" value="02/15/15T03:35">

However the issue is that it does not seem to populate the value of the element and just shows the normal blank values?

My format that datetime-local seems to show on Chrome is dd/mm/Y, --:-- (presumably hours:minutes)

Any help is appreciated as to the correct format?

Thanks!

2 Answers 2

9

The correct format shoud be something like this YYYY-MM-DDTHH:MM or YYYY-MM-DDTHH:MM:SS where T is a string literal T Example

2016-02-01T03:35 or 2016-02-01T03:35:57

<input type="datetime-local" id="early" name="early" value="2016-02-01T03:35">

You can read and check the format here

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

2 Comments

if you are using Java for HTML generation, you should apply a pattern for your Date fields pattern = "yyyy-MM-dd'T'HH:mm:ss". Read more
Generally speaking, when using Java 8 or higher (or JSP) to produce HTML output, java.time.format.DateTimeFormatter.ISO_LOCAL_DATE_TIME formatter would yield the necessary datetime-local value format.
1

You should format your value according to RFC 3339 as written here - https://www.w3.org/TR/html-markup/datatypes.html#form.data.datetime-local

The following parts, in exactly the following order:
A date.
The literal string "T".
A time.

Example: 1985-04-12T23:20:50.52 1996-12-19T16:39:57

So try

<input type="datetime-local" id="early" name="early" value="2015-02-15T03:35:00">

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.