Project / Support Center
Welcome, Guest. Please login or register. July 16, 2019, 03:51: AM
Home Help Search Login Register
D-Web Web Site Creator D - Web Web Site Creator On-line HTML Editor No Programming knowledge required. Web Global Net PayPal-Cart Shopping Cart System PayPal - Kart Shopping Cart System for E-Commerce over the internet, that's easy to use. Web Global Net Newsletter Manager Newsletter Manager On-line Newsletter Creator with Email Subscriber Management.
Ring Central Discount
Web Global Net Web Application & Web Development Project Center  |  Technical Issues  |  Javascripting  |  Topic: Display local Time 0 Members and 1 Guest are viewing this topic. « previous next »
Pages: [1] Go Down Send this topic Print
Author Topic: Display local Time  (Read 4460 times)
admin
Administrator
******
Offline Offline

Posts: 155


« on: December 23, 2016, 02:19: PM »

Found this JS that appears to work in displaying the correct local time on a page - used it on a php reporting page only tested it for EST because php can only use server time which in our case was always 5 hours off of GMT. Apparently when printing this will print the time out twice - not sure why or how to fix it yet.

<script type="text/javascript">
var currentTime = new Date()
var hours = currentTime.getHours()
var minutes = currentTime.getMinutes()

if (minutes < 10){
  minutes = "0" + minutes;
}
var suffix = "AM";
if (hours >= 12) {
suffix = "PM";
hours = hours - 12;
}
if (hours == 0) {
hours = 12;
}

document.write("" + hours + ":" + minutes + " " + suffix + "");
</script>


Use this

<?php echo date('F') ?> <?php echo date('d') ?> <?php echo date('Y') ?> -  
             <script type="text/javascript">
var currentTime = new Date()
var hours = currentTime.getHours()
var minutes = currentTime.getMinutes()

if (minutes < 10){
  minutes = "0" + minutes;
}
var suffix = "AM";
if (hours >= 12) {
suffix = "PM";
hours = hours - 12;
}
if (hours == 0) {
hours = 12;
}

document.write("" + hours + ":" + minutes + " " + suffix + "");
</script>

To produce this

December 23 2016 - 9:31 AM
« Last Edit: December 23, 2016, 04:59: PM by admin » Report to moderator   Logged

The Unknown Webmaster
Pages: [1] Go Up Send this topic Print 
Web Global Net Web Application & Web Development Project Center  |  Technical Issues  |  Javascripting  |  Topic: Display local Time « previous next »
Jump to:  


Login with username, password and session length
Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!