i am the owner of a faucet website(https://trx.faucetcoin.rf.gd/), i want to display the server time on the website, my website is written in php.
i am using these lines of code in my website to display the time
Date/Time:
var dt = new Date(); document.getElementById("datetime").innerHTML = dt.toLocaleTimeString();
but the time displayed is in 12 hour clock, i want the website to show 24 hour time. please help me, thanks in advance
CodePudding user response:
For your case, if you want client side time, just set hour12: false e.g. dt.toLocaleTimeString("en-US", {hour12: false});
So the code (JS) will be:
<div id=datetime style="width:100px;"></div>
<script>
var dt = new Date();
document.getElementById("datetime").innerHTML=(dt.toLocaleTimeString("en-US", {hour12: false}));
</script>
However, if you want server time, you need to use server side script, For example PHP
<?php
echo date("F j, Y, G:i:s");
?>
or , if you just want the time (in 24-hour format), then
<?php
echo date("G:i:s");
?>