User Control Panel
Advertisements

HELP US, HELP YOU!

Time::Zone and Time::Format

 
Post new topic   Reply to topic    Bot Depot Forum Index -> Perl
View unanswered posts
Author Message
Cer
Upgraded Agent
Upgraded Agent


Joined: 03 Feb 2004
Posts: 3776
Location: Michigan
Reputation: 146.9
votes: 4

PostPosted: Sat Mar 26, 2005 6:56 pm    Post subject: Reply with quote

A useful combination of modules to have around is Time::Zone and Time::Format. Time::Zone offers methods such as figuring the time offset (from GMT) of a time zone, and Time::Format makes it easy to get a timestamp formatted how you want it--not localtime's format.

For example, if you want to see the current date/time on the Pacific coast of North America:
Code:
use Time::Format qw(time_format);<br />use Time::Zone;<br /><br /># Get the current GM time.<br />my $time = time();<br /><br /># Offset for PST (Pacific Standard Time).<br />my $offset = tz_offset ('PST');<br />$time += $offset; # modify GM time with this offset.<br /><br /># Get the time stamp!<br />my $stamp = time_format ('Weekday, Month d yyyy @ H:mm:ss AM');<br /># might return something like "Saturday, March 26 2005 @ 1:00:21 PM"


So with Time::Zone and Time::Format, you can quickly and easily begin including time zones into your bot. Your user can define their own time zone, and the bot can make changes in its schedule for that user's time (for example, you can make an appointment reminder, or you can always know your user's time -- so if they're online at 1 in the morning the bot can ask if they're tired or not... things like that).

You can download the modules from CPAN (maybe PPM too, haven't really tried). The module page that's probably of more interest is the one for Time::Format, http://search.cpan.org/~roode/Time-Format-1.00/Format.pm, as it has a table of all the "keywords" to be used when getting a time format:

Code:
    yyyy       4-digit year<br />    yy         2-digit year<br /><br />    m          1- or 2-digit month, 1-12<br />    mm         2-digit month, 01-12<br />    ?m         month with leading space if < 10<br /><br />    Month      full month name, mixed-case<br />    MONTH      full month name, uppercase<br />    month      full month name, lowercase<br />    Mon        3-letter month abbreviation, mixed-case<br />    MON  mon   ditto, uppercase and lowercase versions<br /><br />    d          day number, 1-31<br />    dd         day number, 01-31<br />    ?d         day with leading space if < 10<br />    th         day suffix (st, nd, rd, or th)<br />    TH         uppercase suffix<br /><br />    Weekday    weekday name, mixed-case<br />    WEEKDAY    weekday name, uppercase<br />    weekday    weekday name, lowercase<br />    Day        3-letter weekday name, mixed-case<br />    DAY  day   ditto, uppercase and lowercase versions<br /><br />    h          hour, 0-23<br />    hh         hour, 00-23<br />    ?h         hour, 0-23 with leading space if < 10<br /><br />    H          hour, 1-12<br />    HH         hour, 01-12<br />    ?H         hour, 1-12 with leading space if < 10<br /><br />    m          minute, 0-59<br />    mm         minute, 00-59<br />    ?m         minute, 0-59 with leading space if < 10<br /><br />    s          second, 0-59<br />    ss         second, 00-59<br />    ?s         second, 0-59 with leading space if < 10<br />    mmm        millisecond, 000-999<br />    uuuuuu     microsecond, 000000-999999<br /><br />    am   a.m.  The string "am" or "pm" (second form with periods)<br />    pm   p.m.  same as "am" or "a.m."<br />    AM   A.M.  same as "am" or "a.m." but uppercase<br />    PM   P.M.  same as "AM" or "A.M."<br /><br />    tz         time zone abbreviation

_________________
Current Site (2008) http://www.cuvou.com/
Back to top
M4RTIN
Member
Member


Joined: 31 Dec 2004
Posts: 134

Reputation: 19.2Reputation: 19.2

PostPosted: Sun Mar 27, 2005 7:32 am    Post subject: Reply with quote

Ah cool. Look's cool. Ill use this in my bot. Smile
Back to top
dan0211
Not Yet a God
Not Yet a God


Joined: 23 Dec 2003
Posts: 395

Reputation: 37.8Reputation: 37.8Reputation: 37.8Reputation: 37.8

PostPosted: Sun Mar 27, 2005 12:04 pm    Post subject: Reply with quote

OOh, cool. I was looking for something like this the other day. Thanks Cer
Back to top
Display posts from previous:   
Post new topic   Reply to topic    Bot Depot Forum Index -> Perl All times are GMT
Page 1 of 1

 



Protected by phpBB Security phpBB-TweakS
phpBB Security Has Blocked 9 Exploit Attempts.
Antispam Captcha Mod by phpbb-security.com
Powered by phpBB © 2001, 2005 phpBB Group