burger menu icon
WillMaster

WillMasterBlog > Perl

FREE! Coding tips, tricks, and treasures.

Possibilities weekly ezine

Get the weekly email website developers read:

 

Your email address

name@example.com
YES! Send Possibilities every week!

Seeing the Future with Perl

Adjusting time forwards (and backwards) is easy with Perl.

But before we start playing around with the future, let's determine exactly what time it is now — to the second (according to the server).

my ($second,
    $minute,
    $hour,
    $month_day,
    $month,
    $year,
    $week_day,
    $year_day,
    $is_DST) = localtime;

That snippet retrieves a lot of information about this moment. The same information can be retrieved for any future or past moment.

The $second and $minute variables contain a number 0-59, the $hour variable 0-23.

The $month_day variable contains the calendar day of the month (the number, not the day itself :).

The $month variable contains a number 0-11. January is 0 and December is 11.

The $year variable contains the current 4-digit year minus 1900. Thus, year 2005 would be represented as "105".

The $week_day variable contains a number 0-6. Sunday is 0, Monday is 1, and Saturday is 6.

The $year_day variable contains a count of the number of days elapsed since January 1 of the current year. January 1 is 0, January 2 is 1, January 31 is 30, February 1 is 31, February 2 is 32, and so forth.

The $is_DST variable is either empty or it contains a non-zero number (usually the digit 1). If it contains a non-zero number, it is Daylight Savings Time. If empty, it is not Daylight Savings Time.

Notice that the localtime function retrieves 9 items of information. If you only need only one item, the information can be retrieved independently.

The 9 items the localtime function retrieves can be numbered 0 through 8. Thus, the day of the week number would be number 6.

This retrieves the day of the week number:

my $WeekDay = (localtime)[6];

Now, let's see the future.

A future moment is determined by adding seconds to the current system time.

The current system time is retrieved with the time function.

This snippet adds a years worth of seconds to the current system time, then prints the day of the week for that future.

my $then = time;
$then += 60 * 60 * 24 * 365;
my $ThenWeekDay = (localtime($then))[6];
print $ThenWeekDay;

The value of the $now variable, which contains a system time number of a time in the future, is passed to the localtime function, which then returns the day of the week for that future time.

See how easy it is to see the future with Perl :)

Will Bontrager

Was this blog post helpful to you?
(anonymous form)

Support This Website

Some of our support is from people like you who see the value of all that's offered for FREE at this website.

"Yes, let me contribute."

Amount (USD):

Tap to Choose
Contribution
Method


All information in WillMaster Blog articles is presented AS-IS.

We only suggest and recommend what we believe is of value. As remuneration for the time and research involved to provide quality links, we generally use affiliate links when we can. Whenever we link to something not our own, you should assume they are affiliate links or that we benefit in some way.

Recent Articles in the Library

Simple CSS Rotate

Rotate divs, tables, and even characters. Specify the number of degrees or fraction of a turn, and you're good to go.

Avoid Expired SSL Certificate

Check the expiration date of your domain's SSL certificate

Image Zoom on Hover

Zoom the image with a hover. CSS. No JavaScript.

The INS and DEL Tags

The INS and DEL tags come in mighty handy to display editing marks and to emphasize ideas with HTML markup.

Viewing HTML Source Code

Three ways to view HTML source code.

The HTML address Tag

The address tag is used to present an address to the site user. It also makes the address available to website search engines.

Rotate

The CSS 'rotate' property is a versatile way to rotate elements.

How Can We Help You? balloons
How Can We Help You?
bullet Custom Programming
bullet Ready-Made Software
bullet Technical Support
bullet Possibilities Newsletter
bullet Website "How-To" Info
bullet Useful Information List

© 1998-2001 William and Mari Bontrager
© 2001-2011 Bontrager Connection, LLC
© 2011-2026 Will Bontrager Software LLC