Jump to content

How to Print Current Local System Time in web page?


sivanath.nagendran

Recommended Posts

Printing the server's time in PHP:

echo date('h:i A'); //something like 12:23 PM

Printing the user's time in javascript:

timeStamp = new Date();
var hours = timeStamp.getHours();
meridiem = (hours < 12) ? ' AM' : ' PM';
hours = (Hours > 12) ? hours -= 12 : hours;
var mins = timeStamp.getMinutes();
mins = (mins<10) ? '0'+mins : mins;
document.write(hours + ':' + mins + meridiem');
Link to comment
Share on other sites

I did show you the code.

What do you mean by "Railway time (Second by second automatically increased)"? If you mean you want to have the time actually change on the web page in real time, then that is javascript. There are many free scripts available - just do a search for "javascript clock" or something to that effect.
Link to comment
Share on other sites

As already stated in this thread - there is no way for PHP to know the user's local time. PHP can only retrieve the time of the server it is running on. To do what you are asking you need to implement some functionality so they can set their timezone and have the system save that somewhere, such as a database. Then you could show the user their local time by retrieving the servers time and offsetting it based upon the user's timezone.
Link to comment
Share on other sites

[quote author=sivanath.nagendran link=topic=117263.msg479041#msg479041 date=1165326109]
I could store the current time into Database, whenever the user should press Submit button.[/quote]

Just so we are clear, you can't store the current time for the user unless you use javascript to populate the field to be submitted or you specificly ask the user for their timezone.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.