Perl set date

Code examples

3
0

perl get date

# 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 $FormattedTime = $local_time->strftime('<FormatOfDateTime>');

# example 
use POSIX;
use Time::Piece;
my $CurTime = localtime();
print "[CurTime:$CurTime]\n";

# Note: for formatting, search Perl DateTime Formatting
2
0

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";
1
0

perl set date

# For Perl only

# syntax
use Time::Piece;
Time::Piece->strptime('<Date-time-input>', '<format-of-input>');

# examples (for: 25 May 1994 13:31:18)

# OPTION A
use Time::Piece;
my $date_1 = Time::Piece->strptime('1994-05-25 13:31:18', '%Y-%m-%d %X');
print $date_1 . "\n";

#OPTION B
use Time::Piece;
my $date_2 = Time::Piece->strptime('13:31:18 25/05/1994', '%X %d/%m/%Y');
print $date_2 . "<---\n";

# For more details on formatting symbols (%...), please scroll to the 
# bottom of "https://www.tutorialspoint.com/perl/perl_date_time.htm"

Similar pages

Similar pages with examples

In other languages

This page is in other languages

Русский
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
中文
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................
Балгарскі
..................................................................................................................
Íslensk
..................................................................................................................

Popular in the category

Popular pages with examples in the category