I was surprised that Perl does not have a convenient oneliner to get a timestamp fast enough, such as Ruby has. Nonetheless I did not give up and researched a bit to come up with the following:
my @now = localtime; sprintf("%d%02d%02d",$now[5]+1900,$now[4]+1,$now[3]);
This outputs something like “20091006”.
Though this is a two-liner, it is best I have found this far.
Use strftime !!!
strftime(“%Y-%m-%d %H:%M:%S”,(localtime(time)));
LikeLike
Thanks, Miguel,
But one would first need include the POSIX module, which would make it still a two-liner with the overhead of module loading.
If POSIX is already loaded, then of course
strftime
would be shorter.LikeLike