简体   繁体   中英

How can I display world time in javascript using php time() as a base time?

How can I display time of different countries using javascript? I'm trying to use PHP (America/New_York) to get a baseTime, pass it to javascript and then display different time for respective countries.

<?php
print '
<script type="text/javascript">
var baseTime = "'. time(). '";

//javascript functions
function australiaTime(){

// what do I do here to convert baseTime into australia time?

}//function

function usaTime(){  }

function IndiaTime(){ }

function hongkongTime(){  }

function londonTime(){  }

function japanTime(){ }



</script>
';
?>

I was looking at some world time examples, but they all use client side PC time to do whatever they are doing. What if PC clock is not correctly set? What can I do here?

you can use library momentjs : http://momentjs.com/timezone/

example :

var newYork    = moment.tz("<?=date("Y-m-d h:i") ?>", "America/New_York");
var losAngeles = newYork.clone().tz("America/Los_Angeles");
var london     = newYork.clone().tz("Europe/London");

newYork.format();    // 2014-06-01T12:00:00-04:00
losAngeles.format(); // 2014-06-01T09:00:00-07:00
london.format();     // 2014-06-01T17:00:00+01:00

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM