473,397 Members | 1,950 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

A clock on my web page that shows the time where I am, not the user?

w33nie
56
I'd like to put a clock on my web site, that shows the time where I am, not where the user is.
I found a regular clock with google, that shows the time of the user's system clock, so I thought it might be able to be tweaked to show the time where I am.

I live in the UK at the moment, so right now we're on UTC+1. But I travel around a fair bit, so I was wondering if i'd be able to have the time zone it is displaying coded in PHP, & therefore changeable from my php CMS?

Any help at all is welcome.


Here's the code I mentioned:
(from here - http://www.nippersoft.com/Script/htmlclock.htm)
Expand|Select|Wrap|Line Numbers
  1. <script language = "JavaScript">
  2. function tick()  {
  3. var hours, minutes, seconds, ap;
  4. var intHours, intMinutes, intSeconds;
  5. var today;
  6.  
  7. today = new Date();
  8.  
  9. intHours = today.getHours();
  10. intMinutes = today.getMinutes();
  11. intSeconds = today.getSeconds();
  12.  
  13. if (intHours == 0) {
  14. hours = "12:";
  15. ap = "Midnight";
  16. } else if (intHours < 12) {
  17. hours = intHours+":";
  18. ap = "a.m";
  19. } else if (intHours == 12) {
  20. hours = "12:";
  21. ap = "noon";
  22. } else {
  23. intHours = intHours - 12
  24. hours = intHours + ":";
  25. ap = "p.m.";
  26. }
  27. if (intMinutes < 10) {
  28. minutes = "0"+intMinutes+":";
  29. } else {
  30. minutes = intMinutes+":";
  31. }
  32. if (intSeconds < 10) {
  33. seconds = "0"+intSeconds+" ";
  34. } else {
  35. seconds = intSeconds+" ";
  36. }
  37. timeString = hours+minutes+seconds+ap;
  38.  
  39. Clock.innerHTML = timeString;
  40.  
  41. window.setTimeout("tick();", 100);
  42. }
  43. window.onload = tick;
  44. //--></SCRIPT>
  45.  
Apr 4 '08 #1
3 1492
acoder
16,027 Expert Mod 8TB
You can make an Ajax request to the PHP script to get the current time and set the JavaScript clock based on that or you can do this via PHP when the page loads.
Apr 5 '08 #2
w33nie
56
How would i do that? or, what code would I need?
Apr 14 '08 #3
acoder
16,027 Expert Mod 8TB
This thread should help.
Apr 14 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Jacob H | last post by:
Hello all, I'm close to being a novice programmer and I never was good at math. So I'm curious to know ways in which this following code can be made more efficient, more elegant. The code just...
13
by: Peter Hansen | last post by:
I would like to determine the "actual" elapsed time of an operation which could take place during a time change, in a platform-independent manner (at least across Linux/Windows machines). Using...
9
by: Gino Elloso - Philippines | last post by:
Hello, I made a webpage ( @ Geocities Free Webpages ) that contains a mousetrail clock script. I simply copied the script ( including all html tags ) exactly as it was from a source webpage (...
33
by: Pushkar Pradhan | last post by:
I'm using clock() to time parts of my code e.g. clk1 = clock(); /* code */ clk2 = clock(); /* calculate time in secs */ ...... clk1 = clock(); /* code */ clk2 = clock();
12
by: aegis | last post by:
What is wall clock time? the standard doesn't define it but I see its use in past posts on clc. -- aegis
7
by: ruca | last post by:
How can I show a run time clock in my ASP .NET page???? Can anyone have any code to show that? I have a javscript file that have all necessary code for that, but I'm using VB in my ASPX page and I...
30
by: Matt | last post by:
Does clock_t clock() measure real time or process time? Unless I have missed something, Stroustrup's treatment in TC++PL (section D.4.4.1) is none too clear on that question. Is clock()...
5
by: Tmuld | last post by:
Hello, I just need to create a simple clock. I was going to have a plain page with a lable on it. Then point that label to the time: label1.Text = DateTime.Now.ToLongTimeString but that...
5
by: Charles May | last post by:
Anyone have a simple concept for the best way to store timeclock information in a database. I currently have my table set up like this with a typical daily entry. tcID empID Type ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.