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');
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.
Sorry

  But I need code without using any scripting language like java script. Using only php I need the code for that?
  I tried some thing  in my system time is 14.44 but It shows in web page 20.05 etc.. using PHP language?

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.
[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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.