perl datetime formatting
# For Perl only
# syntax
use POSIX;
use Time::Piece;
my $CurTime = localtime(); # <-- Format: Day Month Date HH:MM:SS (ei: Thu May 7 08:45:52 2020)
my $FormattedVal = $CurTime->strftime('<FormatOfDateTime>');
# example - Copy paste everything below this line and run it
use POSIX;
use Time::Piece;
my $CurTime = localtime();
my $Formatted_Year = $CurTime->strftime('%Y');
my $Formatted_Month = $CurTime->strftime('%m');
my $Formatted_Date = $CurTime->strftime('%d');
my $Formatted_Time = $CurTime->strftime('%X');
my $Formatted_Together = $CurTime->strftime('Date:%Y-%m-%d Time:%X');
print "[Formatted_Year-->>$Formatted_Year]\n";
print "[Formatted_Month-->>$Formatted_Month]\n";
print "[Formatted_Date-->>$Formatted_Date]\n";
print "[Formatted_Time-->>$Formatted_Time]\n";
print "[Formatted_Together-->>$Formatted_Together]\n";
Are there any code examples left?
New code examples in category Perl
-
Perl 2022-01-31 06:16:22 perl format decimal 2 places not rounding
-
Perl 2022-01-30 18:35:07 perl id number validation south africa
-
Perl 2022-01-22 12:46:02 perl add key value pair to hash
-
Perl 2021-11-22 01:55:21 unique in perl
-
Perl 2021-11-13 15:55:08 perl lowercase
-
Perl 2021-11-11 03:30:19 perl write to file
-
Perl 2021-11-06 22:53:11 perl for loop
-
Perl 2021-11-05 17:26:13 perl sprintf YYYYMMDD sample