Input DatetimeLocal value attribute

Definition and Usage

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

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

See also:

HTML Reference Manual:Attribut value de l'élément <input> HTML

Instance

Example 1

Set the local date and time for 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 the defaultValue and value attributes:

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

Try It Yourself

Syntax

Return the value attribute:

datetimelocalObject.value

Set the 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 (for example, 2023)
  • MM - Month (for example, 02 represents February)
  • DD - Day of the month (for example, 15)
  • T - If a time is specified, then it is a required separator
  • hh - Hour (for example, 22 represents 10 PM)
  • mm - Minute (for example, 55)
  • ss - Second (for example, 06)
  • ms - Millisecond (for example, 520)

Détails techniques

Valeur de retour : Valeur de chaîne, représentant la date et l'heure du champ de date et heure local.

Support du navigateur

Les numéros dans le tableau indiquent la version du navigateur qui prend en charge cette propriété pour la première fois.

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

Attention :L'élément <input type="datetime-local"> ne montre aucun champ de date ou de calendrier dans Firefox.