This is likely a duplicate of Where can I find documentation on formatting a date in JavaScript?
Presumably you wish to set the value of some attribute to a time value, then replace the element content with a formatted string. You can use the HTMLTime element, but could just as easily use a span or similar element:
window.onload = function() {
// Use span element
var timeSpan = document.getElementById('timeSpan');
timeSpan.textContent = new Date(+timeSpan.dataset.timevalue).toLocaleString();
// Use time element
var timeElement = document.getElementById('timeElement');
timeElement.textContent = new Date(+timeElement.getAttribute('datetime')).toLocaleString();
}
<!-- Use ISO 8601 string by default, replace with toLocaleString -->
<span id="timeSpan" data-timevalue="1497026760000">2017-06-09T16:46:00.000Z</span><br>
<time id="timeElement" datetime="1497026760000">2017-06-09T16:46:00.000Z</time>
However, there is no guarantee that a browser will honour the host system settings for date formatting in any respect. For me, the above shows:
- 6/10/2017, 2:46:00 AM in Safari
- 6/10/2017, 2:46:00 AM in Chrome
- 10/06/2017, 2:46:00 am in Firefox
So the bottom line is that you are much better to set an unambiguous format (e.g. 10 June, 2017 or June 10, 2017) than leave it up to the host to localise for you.