How to show local time and date

XML, Perl, Python, and other languages can be discussed here, even if it isn't PHP (We might forgive you).

Moderator: General Moderators

Post Reply
szms
Forum Contributor
Posts: 101
Joined: Thu Jun 26, 2003 12:23 pm

How to show local time and date

Post 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.
User avatar
Skittlewidth
Forum Contributor
Posts: 389
Joined: Wed Nov 06, 2002 9:18 am
Location: Kent, UK

Post by Skittlewidth »

Can't you just use the time from the server your website is hosted on?
szms
Forum Contributor
Posts: 101
Joined: Thu Jun 26, 2003 12:23 pm

Post 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.
Draco_03
Forum Regular
Posts: 577
Joined: Fri Aug 15, 2003 12:25 pm
Location: Montreal, Canada

Post 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 :))
User avatar
Skittlewidth
Forum Contributor
Posts: 389
Joined: Wed Nov 06, 2002 9:18 am
Location: Kent, UK

Post 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:

Code: Select all

Tue, 27 Jul 2004 2:42 PM
or just

Code: Select all

<?php echo date("g:i A") ?>
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.
szms
Forum Contributor
Posts: 101
Joined: Thu Jun 26, 2003 12:23 pm

Post 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.
User avatar
Skittlewidth
Forum Contributor
Posts: 389
Joined: Wed Nov 06, 2002 9:18 am
Location: Kent, UK

Post 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! :oops:

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
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

Well, szms, what language do you use? (CGI isn't a language)
Draco_03
Forum Regular
Posts: 577
Joined: Fri Aug 15, 2003 12:25 pm
Location: Montreal, Canada

Post by Draco_03 »

i guess it's pearl.. most commonly used with cgi
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post 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;
Post Reply