Format Date and Time in Perl

PERLServer Side ProgrammingProgramming Scripts

You can use localtime() function in Perl to get a list of 9-elements and later you can use the printf() function to format date and time based on your requirements as follows −

Example

 Live Demo

#!/usr/local/bin/perl
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime();
printf("Time Format - HH:MM:SS\n");
printf("%02d:%02d:%02d", $hour, $min, $sec);

Output

When the above code is executed, it produces the following result −

Time Format - HH:MM:SS
06:58:52
raja
Published on 29-Nov-2019 06:32:04
Advertisements