Programming dealing with time and date. - Help me out, I'm new to this stuff.

They have: 453 posts

Joined: Jan 1999

hi,

just get the "now"-time with:
sub _now
{
my ( $offset ) = @_;
my ( $sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst ) = gmtime( time + $offset*3600 );
$year+=1900;
$mon+=1;
return( sprintf( "%04u-%02u-%02u %02u:%02u:%02u", ( $year, $mon, $mday, $hour, $min, $sec ) ) );
}

the first parameter is the users-time-offset in hours.

think it works.
ciao
Anti

----------
ps:watch my work in progress at
http://webhome.nu/

They have: 5,633 posts

Joined: Jan 1970

it works.... Smiling
but i would add the server-time to the database, you will probably want to know the time your web-site has it's heaviest traffic. if you only save the local-times, it won't be easy..
cu
patrick

They have: 112 posts

Joined: Apr 1999

Hi,
I need some help on programming logic and pointers because I'm fairly new to the date/time of Perl programming. This is what I'm going to do:
I'm going to have a list of subscribers. Whenever the subscriber visits my site, I'll try to show their current time depending on their location.
I know I'm going to need their GMTs, but I'm quite confused right now, what values should I keep track in the database? And I'm not quite familar with the GMT stuff.
Anyone has written this kind of program which deals with GMT, time and dates?
Thanks in advance.

----------
Elara - Webmasters' Guide
http://elara.hypermart.net/

They have: 453 posts

Joined: Jan 1999

Hi Pat,

as far is I understood elara she just wanted to show the time to the user.
And she wanted to know which data she'll need from her database to calc the users localtime.
The offset (to gmt) and gmt are the only things needed for this.

The timestamps in my logfiles are always gmt.

ciao
Anti

They have: 112 posts

Joined: Apr 1999

anti,
Thanks for your help, upon looking the code, I think it will work. I'll test it out shortly.
I have one more thing to clarify. I possess something extra that female don't. Smiling Never mind about it, gender doesn't matters to me, proud to be a man though Smiling. No intention to offense the females here... Smiling
Later.

----------
Elara - Webmasters' Guide
http://elara.hypermart.net/

They have: 453 posts

Joined: Jan 1999

hi elara,

sorry if i "guessed" your gender wrong. it's just that names ending in "a" are usually female.

sorry.
ciao
anti

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.