javascript - How can I show the current time from a different timezone on my webpage? -
i want show time timezone chosen me on webpage. found way show current time it's presented here http://www.webestools.com/ftp/ybouane/scripts_tutorials/javascript/date_time/date_time.html :
<!doctype html public "-//w3c//dtd xhtml 1.0 strict//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <title>display date , time in javascript</title> <script type="text/javascript" src="date_time.js"></script> </head> <body> <span id="date_time"></span> <script type="text/javascript">window.onload = date_time('date_time');</script> </body> </html>
and js:
function date_time(id) { date = new date; year = date.getfullyear(); month = date.getmonth(); months = new array('january', 'february', 'march', 'april', 'may', 'june', 'jully', 'august', 'september', 'october', 'november', 'december'); d = date.getdate(); day = date.getday(); days = new array('sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday'); h = date.gethours(); if(h<10) { h = "0"+h; } m = date.getminutes(); if(m<10) { m = "0"+m; } s = date.getseconds(); if(s<10) { s = "0"+s; } result = ''+days[day]+' '+months[month]+' '+d+' '+year+' '+h+':'+m+':'+s; document.getelementbyid(id).innerhtml = result; settimeout('date_time("'+id+'");','1000'); return true; }
but if understand correctly - shows current time timezone of viewer of page. when logs in there e.g. australia - see result, , guy poland see sth different. present on webpage current time in fixed timezone, let's e.g. in new york. how should modify script expected results? thanks!
you can use moment-timezone convert time differnt timezone
here example:
function totimezone(time, zone) { var format = 'yyyy/mm/dd hh:mm:ss zz'; return moment(time, format).tz(zone).format(format); }
Comments
Post a Comment