Page 1 of 1
How to show local time and date
Posted: Tue Jul 27, 2004 7:36 am
by szms
Well I am not interested in getting time and date from users computer for my web site because sometime it does not give the right information. So do you have any other idea how I can get local time and date (approximately accurate) for my web site. Necessary code will be very helpfull. Thank you.
Posted: Tue Jul 27, 2004 8:05 am
by Skittlewidth
Can't you just use the time from the server your website is hosted on?
Posted: Tue Jul 27, 2004 8:28 am
by szms
Well I don't know how to get it from my server. Could you please let me know in detail about it. Thank you.
Posted: Tue Jul 27, 2004 8:41 am
by Draco_03
Here you have a super dooper script thatgives you the difference from the server time and the lcoal one. (tweak it so you just get the server time

)
Posted: Tue Jul 27, 2004 8:46 am
by Skittlewidth
Use the date() function.
http://uk2.php.net/manual/en/function.date.php
will show you how to use it, but basically if you wanted to echo the time and date on to your webpage you would have:
Code: Select all
<?php echo date("D, d M Y g:i A") ?>
This would output:
or just
for the time.
The URL above will show you a list of all the formatting options including how to adjust the timezone if your server is in a different country. Hope this helps.
Posted: Tue Jul 27, 2004 8:52 am
by szms
Well my server only support CGI not PHP. So could you please let me know any other alternative way to do the same. Tahnk you.
Posted: Tue Jul 27, 2004 8:57 am
by Skittlewidth
Sorry, I saw that you couldn't use PHP from your other post after I'd replied. I just took for granted that you'd be asking from a PHP perspective!
I'm afraid you've reached the limit of my scripting knowledge if its not php related, so I'll let someone else answer this one!
If the date and time is just for decorative purposes, why not have a look at
http://www.dynamicdrive.com/dynamicindex6/index.html for a script that displays date and time, its mostly javascript but they might have cgi stuff
Posted: Tue Jul 27, 2004 9:08 am
by Weirdan
Well, szms, what language do you use? (CGI isn't a language)
Posted: Tue Jul 27, 2004 9:20 am
by Draco_03
i guess it's pearl.. most commonly used with cgi
Posted: Tue Jul 27, 2004 9:35 am
by Weirdan
just out of perdoc.com FAQs:
Code: Select all
use POSIX qw(strftime);
$now_string = strftime "%a %b %e %H:%M:%S %Y", localtime;