Input DatetimeLocal value Attribute

Definition and Usage

value Sets or returns the value of the value attribute of the local date-time field.

HTML value attribute specifies the local date and time for the local date-time field.

See Also:

HTML Reference Manual:HTML <input> value Attribute

Instance

Example 1

Set the local date and time of the date-time field:

document.getElementById("myLocalDate").value = "2023-02-15T18:15:30.520";

Try It Yourself

Example 2

Get the local date and time of the date-time field:

var x = document.getElementById("myLocalDate").value;

Try It Yourself

Example 3

An example showing the difference between defaultValue and value attributes:

var x = document.getElementById("myLocalDate");
var defaultVal = x.defaultValue;
var currentVal = x.value;

Try It Yourself

Syntax

Return value attribute:

datetimelocalObject.value

Set value attribute:

datetimelocalObject.value = YYYY-MM-DDThh:mm:ss.ms

Attribute Value

Value Description
YYYY-MM-DDThh:mm:ss.ms

Specify the date and time.

Component Description:

  • YYYY - Year (e.g., 2023)
  • MM - Month (e.g., 02 represents February)
  • DD - Day of the month (e.g., 15)
  • T - If a time is specified, then it is a required separator
  • hh - Hours (e.g., 22 represents 10 PM)
  • mm - Minutes (e.g., 55)
  • ss - Seconds (e.g., 06)
  • ms - Milliseconds (e.g., 520)

Technical Details

Return Value: A string value representing the date and time of the local date and time field.

Browser Support

The numbers in the table indicate the first browser version that fully supports this attribute.

Chrome Edge Firefox Safari Opera
Chrome Edge Firefox Safari Opera
Support 10.0 Support Support Support

Note:The <input type="datetime-local"> element does not display any date and time fields/calendars in Firefox.