The value
property sets or gets the value attribute of a datetime field.
value |
No | No | No | No | No |
Return the value property.
var v = datetimeObject.value
Set the value property.
datetimeObject.value=YYYY-MM-DDThh:mm:ssTZD
Value | Description |
---|---|
YYYY-MM-DDThh:mm:ssTZD | Set the date and/or time.
|
A String type value representing the date and time of the datetime field.
The following code shows how to get the date and time of a datetime field.
<!DOCTYPE html>
<html>
<body>
<!-- w w w. j av a 2s . c o m-->
Date: <input type="datetime" id="myDatetime" value="2014-02-06T10:27Z">
<button onclick="myFunction()">test</button>
<p id="demo"></p>
<script>
function myFunction() {
var x = document.getElementById("myDatetime").value;
document.getElementById("demo").innerHTML = x;
}
</script>
</body>
</html>
The code above is rendered as follows:
The following code shows how to set a date and time for a datetime field.
<!DOCTYPE html>
<html>
<body>
Date: <input type="datetime" id="myDatetime">
<button onclick="myFunction()">test</button>
<!--from ww w.j a v a2 s . c o m-->
<p id="demo"></p>
<script>
function myFunction() {
document.getElementById("myDatetime").value = "2014-01-12T11:12Z";
}
</script>
</body>
</html>
The code above is rendered as follows: