Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!

Idiom #61 Get current date

Assign to the variable d the current date/time value, in the most standard type.

$d = time;
$d = time;

my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($d);

Builtin function time gets the number of seconds since epoch. localtime converts to date and time components and returns them as a list. For an OO interface, see Time::Piece.
use Time::Piece;

$d = localtime;		# local time as a Time::Piece object
say $d->ymd;		# yyyy-mm-dd format
say $d->datetime;	# ISO 8601 format

$g = gmtime;		# GMT as a Time::Piece object

Importing CPAN module Time::Piece replaces perl builtin functions localtime and gmtime with object-oriented equivalents.
with Ada.Calendar;
D : Ada.Calendar.Time := Ada.Calendar.Clock;

New implementation...
< >
programming-idioms.org