Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get the current date in ISO format using Perl?

Tags:

What's the most efficient way to get the current date in ISO format (e.g. "2010-10-06") using Perl?

like image 764
planetp Avatar asked Oct 06 '10 17:10

planetp


People also ask

How do I get today's date in Perl?

localtime() function in Perl returns the current date and time of the system, if called without passing any argument.

How can I get current date from ISO?

Use the Date. toISOString() Method to Get Current Date in JavaScript. This method is used to return the date and time in ISO 8601 format. It usually returns the output in 24 characters long format such as YYYY-MM-DDTHH:mm:ss.

How do I change the date format in Perl?

You can use the POSIX function strftime() to format date and time with the help of the following table.


1 Answers

Most efficient for you or the computer?

For you:

use POSIX qw/strftime/;

print strftime("%Y-%m-%d", localtime), "\n";

For the Computer:

my @t = localtime;
$t[5] += 1900;
$t[4]++;

printf "%04d-%02d-%02d", @t[5,4,3];
like image 192
Chas. Owens Avatar answered Oct 28 '22 11:10

Chas. Owens