in reply to seconds since the epoch
You can do it using localtime and printf or POSIX::strftime. POSIX is a core module. FYI POSIX::mktime converts sec,min,hr,d,m,y to epoch time if you want to go the other way.
my $time = time(); my ($sec,$min,$hour,$day,$mon,$year) = localtime($time); $year+= 1900; $mon += 1; $year = substr $year, 1; printf "%02d/%02d/%02d %02d:%02d\n", $year, $mon, $day, $hour, $min; use POSIX qw(strftime); print strftime("%y/%m/%d %H:%M\n", localtime); print strftime(" POSIX strftime a %a A %A b %b B %B c %c d %d H %H I %I j %j m %m M %M p %p S %S U %U w %w W %W x %x X %X y %y Y %Y Z %Z ", localtime); __DATA__ 08/03/16 11:37 08/03/16 11:37 POSIX strftime a Sun A Sunday b Mar B March c 3/16/2008 11:37:48 AM d 16 H 11 I 11 j 076 m 03 M 37 p AM S 48 U 11 w 0 W 10 x 3/16/2008 X 11:37:48 AM y 08 Y 2008 Z Vulcan Standard Time
|
---|