#!/usr/bin/perl -w use strict; use warnings; use POSIX; my($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); $year += 1900; print "$sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst\n"; my $now_string = localtime; print "$now_string\n"; #my $date = strftime "%a %b %e %H:%M:%S %Y", localtime; my $date = strftime "%d-%b-%Y", localtime; print "Date1 is : $date\n"; #$date = strftime "%a-%B-%e", localtime; $date = strftime "%d-%m-%Y", localtime; print "Date2 is : $date\n"; my $time = strftime "%H:%M:%S", localtime; print "Time1 is : $time\n"; #my $time1 = strftime "%h:%m:%s", localtime; my $time1 = strftime "%I:%M:%S", localtime; print "Time2 is : $time1\n"; OUTPUT: 58, 39, 15, 6, 9, 2017, 5, 278, 1 Fri Oct 6 15:39:58 2017 Date1 is : 06-Oct-2017 Date2 is : 06-10-2017 Time1 is : 15:39:58 Time2 is : 03:39:58