Help with JavaScript code to display time from internet

Javascript coding ..

Moderators: macek, egami, gesf

nwabunnia
New php-forum User
New php-forum User
Posts: 4
Joined: Mon Jul 02, 2012 1:00 pm

Help with JavaScript code to display time from internet

Postby nwabunnia » Thu Aug 09, 2012 12:42 am

Please could somebody help me with a script that will display the current time from the internet instead of system/computer time.

I am working on a web based time clocking app and because the system time can be changed, it defeats the whole purpose. If I can get the app to display the internet time ( with a defined time zone) I think it would help.

I am using something like this already:

Code: Select all

var isnMonths=new Array("January","February","March","April","May","June","July","August","September","October","November","December");
var isnDays= new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday");
today=new Date();
hrs=today.getHours();
min=today.getMinutes();
sec=today.getSeconds();
var year=today.getYear();
if (year < 2000)
year = year + 1900;
clckh=""+((hrs>12)?hrs-12:hrs);
clckm=((min<10)?"0":"")+min;
clcks=((sec<10)?"0":"")+sec;
clck=(hrs>=12)?"p.m":"a.m";


And in the page I want it displayed, I use this:

Code: Select all

<script language="JavaScript" type="text/javascript">
document.write("<B>"
+isnDays[today.getDay()]+", "+isnMonths[today.getMonth()]+" "
+today.getDate()+", "+ year + " "+clckh+":"+clckm+" "+clck+"</B>");
</script>


It will just display the system time.

Any suggestions would be appreciated.

Thanks.

User avatar
Nullsig
php-forum Fan User
php-forum Fan User
Posts: 981
Joined: Thu Feb 17, 2011 6:52 am
Location: Racine, WI

Re: Help with JavaScript code to display time from internet

Postby Nullsig » Thu Aug 09, 2012 12:34 pm

You would have to use AJAX to retrieve the time from a remote site.

JavaScript by itself is client side only. Which means that you will only be able to use the client's computer


Return to “JavaScript”

Who is online

Users browsing this forum: No registered users and 0 guests

cron