Skip to content

Instantly share code, notes, and snippets.

@karupanerura
Created March 13, 2012 06:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save karupanerura/2027343 to your computer and use it in GitHub Desktop.
Save karupanerura/2027343 to your computer and use it in GitHub Desktop.
localized strftime in perl
use strict;
use warnings;
use utf8;
use 5.10.0;
use POSIX ();
sub localize_strftime {
my $locale = shift;
my $default = POSIX::setlocale(POSIX::LC_TIME);
POSIX::setlocale(POSIX::LC_TIME, $locale);
my $retval = POSIX::strftime(@_);
POSIX::setlocale(POSIX::LC_TIME, $default);
return $retval;
}
say+localize_strftime('en_US', '%a, %d %b %Y %T %z', localtime(time));
say+localize_strftime('ja_JP.UTF8', '%a, %d %b %Y %T %z', localtime(time));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment