Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Input type DateTime - Value format?

In which format should I put the date and time, for use in the HTML5 input element with datetime type?

I have tried:

  • 1338575502
  • 01/06/2012 19:31
  • 01/06/2012 19:21:00
  • 2012-06-01
  • 2012-06-01 19:31
  • 2012-06-01 19:31:00

None of them seem to work.

like image 682
RobinJ Avatar asked Jun 01 '12 17:06

RobinJ


People also ask

How do I change the date format in input type date?

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.

What is the format of datetime local?

DD/MM/YYYY. MM/DD/YYYY.

How do you write input type time in 24-hour format?

The value of the time input is always in 24-hour format that includes leading zeros: hh:mm , regardless of the input format, which is likely to be selected based on the user's locale (or by the user agent). If the time includes seconds (see Using the step attribute), the format is always hh:mm:ss .


2 Answers

For <input type="datetime" value="" ...

A string representing a global date and time.

Value: A valid date-time as defined in [RFC 3339], with these additional qualifications:

•the literal letters T and Z in the date/time syntax must always be uppercase

•the date-fullyear production is instead defined as four or more digits representing a number greater than 0

Examples:

1990-12-31T23:59:60Z

1996-12-19T16:39:57-08:00

http://www.w3.org/TR/html-markup/input.datetime.html#input.datetime.attrs.value

Update:

This feature is obsolete. Although it may still work in some browsers, its use is discouraged since it could be removed at any time. Try to avoid using it.

The HTML was a control for entering a date and time (hour, minute, second, and fraction of a second) as well as a timezone. This feature has been removed from WHATWG HTML, and is no longer supported in browsers.

Instead, browsers are implementing (and developers are encouraged to use) the datetime-local input type.

Why is HTML5 input type datetime removed from browsers already supporting it?

https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/datetime

like image 59
Sully Avatar answered Sep 16 '22 17:09

Sully


For what it's worth, with iOS7 dropping support for datetime you need to use datetime-local which doesn't accept timezone portion (which makes sense).

Doesn't work (iOS anyway):

 <input type="datetime-local" value="2000-01-01T00:00:00+05:00" /> 

Works:

<input type="datetime-local" value="2000-01-01T00:00:00" /> 

PHP for value (windows safe):

strftime('%Y-%m-%dT%H:%M:%S', strtotime($my_datetime_input)) 
like image 32
Brandon Hill Avatar answered Sep 16 '22 17:09

Brandon Hill