Created
August 16, 2011 05:32
-
-
Save SpringMT/1148489 to your computer and use it in GitHub Desktop.
ex time in bashrc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # perl | |
| function ex_time() { | |
| perl -le ' | |
| use Time::Local; | |
| use DateTime; | |
| my $zone = 'UTC'; | |
| my $time = $ARGV[0] || time(); | |
| if ($time =~ m{^(\d{4})/(\d{2})/(\d{2})-(\d{2}):(\d{2}):(\d{2})$}) { | |
| print("localtime2unixtime"); | |
| print("$time"); | |
| print(timelocal($6, $5, $4, $3, $2-1, $1-1900)); | |
| print("GMT"); | |
| my $dt = DateTime->new(time_zone =>$zone,year=>$1,month=>$2,day=>$3,hour=>$4,minute=>$5,second=>$6); | |
| print($dt->epoch); | |
| exit; | |
| } | |
| my($sec,$min,$hh,$dd,$mm,$yy,$weak,$yday,$opt) = localtime($time); | |
| $yy+=1900; $mm +=1; | |
| print("localtime"); | |
| printf("%04d/%02d/%02d %02d::%02d::%02d\n", $yy, $mm, $dd, $hh, $min, $sec); | |
| #my $dt = DateTime->from_epoch( time_zone => $zone, epoch => $time ); | |
| print("GMT"); | |
| #print($dt->strftime("%Y/%m/%d %H:%M:%S %b %a")); | |
| my @MON = qw( Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec ); | |
| my @WDAY = qw( Sun Mon Tue Wed Thu Fri Sat ); | |
| my($sec, $min, $hour, $mday, $mon, $year, $wday) = gmtime($time); | |
| $year += 1900; | |
| printf("%s, %02d-%s-%04d %02d:%02d:%02d GMT \n", | |
| $WDAY[$wday], $mday, $MON[$mon], $year, $hour, $min, $sec); | |
| ' $1 | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment