POSIX date format in Perl

To make a Perl script portable is to avoid using system commands as much as possible. To deal with date formats actions, you’d better use DateTime or Date::Calc modules.

For a simple formatting of the current date using localtime() Perl function :

#!/usr/bin/perl
use POSIX qw(strftime);
my $date = strftime “%d-%m-%y”, localtime;

Instead of :

my $date = qx(date +%d-%m-%y);

Both work. The first one is more Perlish 😉

More info :
POSIX Function strftime() in Perl
DateTime Perl module
Date::Calc Perl module

Advertisements

Change the time and date in Linux

To change the time and the date, make sure you have root privileges :

To modify the time :

#date -s HH:MM:SS

To modify the date :

#date -s MM/DD/YYYY

If you want to know your BIOS time  and date :

#hwclock

To synchronize BIOS date and time with your system’s date and time :

#hwclock –systohc