&POSIX::strftime .
After Compline, Zaxo
| [reply] [Watch: Dir/Any] |
use Date::Calc;
($year,$month,$day, $hour,$min,$sec) = Today_and_Now([$gmt]);
$final = "$month/$day/$year-$hour:$min:$sec";
| [reply] [Watch: Dir/Any] [d/l] |
If you want to do it in a module-free manner without using pesky intermediate variables, you could do worse than wrapping up sprintf in an anonymous subroutine, which gives something like:
my $date = sprintf '%04d/%02d/%02d-%02d:%02d:%02d',
sub { $_[5]+1900, $_[4]+1, reverse @_[0..3] }->(gmtime($output));
I write this snippet so often I have often toyed with the idea of uploading as a module to CPAN so I can use it where ever I work, but it seems a bit frivolous since I can type it so quickly. What is happening is that the output from gmtime is being passed to an anonymous sub, which modifies two elements, reverses the first few elements taken as a hash slice and throws the rest away. The resulting elements are returned in list context from the sub to sprintf, which, by a miraculous turn of events, is waiting with a format string which will process those values in just the right way.
I really dig this idiom.
oops: I just realised I coded this up to emit the standard ISO date format. Talk about habit. I would avoid using the M/D/Y format: it looks to me as if you're talking about the 7th of January. Which indeed you might be. But others will think you're talking about the 1st of July. I mean, if you're going to the effort of representing times in GMT...
print@_{sort keys %_},$/if%_=split//,'= & *a?b:e\f/h^h!j+n,o@o;r$s-t%t#u' | [reply] [Watch: Dir/Any] [d/l] |
You might want to check out Date::Parse it should give you some easy variables to use and convert to the format you want. Date::Format is another module worth checking out for this. Good Luck
| [reply] [Watch: Dir/Any] |
While this module can introduce a lot of unnecessary overhead, you might want to look at Date::Manip. It can do just about anything you would want with regard to date comparison, manipulation, conversion, etc. Consider it an all-in-one suite of about a dozen other date modules. It's very easy to use, but like I said, high overhead. Specifically, look at the UnixDate() function in this module.
Hope this helps. | [reply] [Watch: Dir/Any] |