Shoutbox

Help with Local time PHP code - Printable Version

-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Skype & Technology (/forumdisplay.php?fid=9)
+---- Forum: Tech Talk (/forumdisplay.php?fid=17)
+----- Thread: Help with Local time PHP code (/showthread.php?tid=54399)

Help with Local time PHP code by Salem on 12-30-2005 at 04:04 PM

I have used the local time script from Dynamic Drive on a webpage, however, on the page i get NaN:NaN:NaN AM where the time should be (when set to short format).

When using the code i chose the PHP mode as the server supports PHP, but it still doesn't work. If the display format is changed to long then i get undefined instead of the server time.

Any ideas?

Thanks in Advance


RE: Help with Local time PHP code by rix on 12-30-2005 at 04:14 PM

I'm not sure, did I understand you correctly, but why don't you just use simple PHP date functions? You can easily show time by doing this:

code:
echo date("H:i:s");

Also take a look at these functions:
date_default_timezone_set()
date_default_timezone_get
date()
RE: RE: Help with Local time PHP code by Salem on 12-30-2005 at 04:17 PM

quote:
Originally posted by rix
I'm not sure, did I understand you correctly, but why don't you just use simple PHP date functions? You can easily show time by doing this:
code:
echo date("H:i:s");

Also take a look at these functions:
date_default_timezone_set()
date_default_timezone_get
date()


Yeh, but im totally new to PHP. If some can help i'd be very greatful
RE: Help with Local time PHP code by hmaster on 12-30-2005 at 04:54 PM

Use the date() function to get the server time -> http://uk2.php.net/manual/en/function.date.php

If you want to set the time to a certain place gmstrftime -> http://uk2.php.net/manual/en/function.gmstrftime.php
You change the locale settings to get the what time you want

If you want GMT time use gmmktime -> http://uk2.php.net/manual/en/function.gmmktime.php


RE: RE: RE: Help with Local time PHP code by rav0 on 12-31-2005 at 01:44 AM

quote:
Originally posted by rix
I'm not sure, did I understand you correctly, but why don't you just use simple PHP date functions? You can easily show time by doing this:
code:
echo date("H:i:s");

quote:
Originally posted by Salem
Yeh, but im totally new to PHP. If some can help i'd be very greatful

You must rename your files to something.php, they can't be something.html for PHP to work (except for exceptions). Sorry if you already knew this.

Inside a file called something.php, put this:
code:
<?php
echo date('g:i A');
?>
Wherever in the file you put it, PHP shpuld make it come out like 12:35 PM (the current time).

Instead of g:i A, you can put other things to have the time in a different format. Refer to date in the PHP manual for the parameters you can use.

Though if you are having problems still, maybe the time is not working on the server.
RE: RE: RE: RE: Help with Local time PHP code by Salem on 01-01-2006 at 08:19 PM

quote:
Originally posted by rav0
You must rename your files to something.php, they can't be something.html for PHP to work (except for exceptions). Sorry if you already knew this.

yes i was aware about this

quote:
Originally posted by rav0
Inside a file called something.php, put this:
code:
<?php
echo date('g:i A');
?>
Wherever in the file you put it, PHP shpuld make it come out like 12:35 PM (the current time).

Instead of g:i A, you can put other things to have the time in a different format. Refer to date in the PHP manual for the parameters you can use.

Though if you are having problems still, maybe the time is not working on the server.


Thanks, this does help.

Will this method constantly update the time, or will it only be accurate on every refresh. The script i tried using updates the time on the webpage constantly.

Salem
RE: Help with Local time PHP code by Ezra on 01-01-2006 at 08:49 PM

This will only be accurate on every refresh, this is the way php works.

For realtime accuracy you should use JavaScript or something.


RE: RE: Help with Local time PHP code by Salem on 01-01-2006 at 08:54 PM

quote:
Originally posted by Ezra
This will only be accurate on every refresh, this is the way php works.

For realtime accuracy you should use JavaScript or something.


Thanks, yeh i thoguth that would be the case. Thanks for the help guys.
RE: Help with Local time PHP code by hmaster on 01-01-2006 at 10:26 PM

JS Date -> http://www.w3schools.com/js/js_obj_date.asp

Realtime JS Clock -> http://www.w3schools.com/js/tryit.asp?filename=tryjs_timing_clock