The value
property sets or gets
the value attribute of a local datetime field.
value |
Yes | No | No | Yes | Yes |
Return the value property.
var v = datetimelocalObject.value
Set the value property.
datetimelocalObject.value=YYYY-MM-DDThh:mm:ss.ms
Value | Description |
---|---|
YYYY-MM-DDThh:mm:ss.ms | Specifies the date and time.
|
A String type value representing the date and time of the local datetime field.
The following code shows how to get the local date and time of a datetime field.
<!DOCTYPE html>
<html>
<body>
<input type="datetime-local" id="myLocalDate" value="2014-11-16T15:25:33">
<button onclick="myFunction()">test</button>
<!--from w w w .j av a2 s . c om-->
<p id="demo"></p>
<script>
function myFunction() {
var x = document.getElementById("myLocalDate").value;
document.getElementById("demo").innerHTML = x;
}
</script>
</body>
</html>
The code above is rendered as follows:
The following code shows how to set a local date and time for a datetime field.
<!DOCTYPE html>
<html>
<body>
<!--from ww w. ja v a 2 s .co m-->
Date: <input type="datetime-local" id="myLocalDate">
<button onclick="myFunction()">test</button>
<p id="demo"></p>
<script>
function myFunction() {
document.getElementById("myLocalDate").value = "2014-01-02T11:22:13.511";
}
</script>
</body>
</html>
The code above is rendered as follows: