Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

how to show 24 hour server time php

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:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

>Solution :

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");
?>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading