#!/usr/bin/perl use warnings; use strict; use Time::Local; ## [11/Jun/2012:23:12:03 +0800] -> 12345667 -> 2012-06-11 23:12:03 my %monhash = ("Jan"=>1,"Feb"=>2,"Mar"=>3,"Apr"=>4,"May"=>5,"Jun"=>6,"Jul"=>7,"Aug"=>8,"Sep"=>9,"Oct"=>10,"Nov"=>11,"Dec"=>12); sub to_Stand_time { my $str = shift @_; my ($sec, $min, $hour, $day, $mon, $year, $wday, $yday, $isdst) = localtime($str); $year = 1900 + $year; $mon = $mon + 1; return sprintf("%s-%02d-%02d %02d:%02d:%02d",$year,$mon,$day,$hour,$min,$sec); } while(<>){ chomp; if(m|^\[(\d+)/(\w+)/(\d+):(\d+):(\d+):(\d+)\s+\+\d+\]$|){ my($d,$m,$y,$h,$mm,$s)=($1,$2,$3,$4,$5,$6); $m = $monhash{$m}; my $ud = Time::Local::timelocal($s,$mm,$h,$d,$m-1,$y-1900); my $dt = to_Stand_time($ud); print STDERR "$_ -> $ud -> $dt\n"; } }
相关推荐
perl一般代码
QDateEditEx 一个Qt QDateEdit小部件,它也可以处理空值
显示时间(datetime) 转换-> UTC时间戳(timestamp),使用calendar.timegm(datetime.timetuple())。 注意: VC下相应的接口是gmtime和_mkgmtime。 代码: # -*- coding: gb2312 -*- # UTC时间转换,最终得到的都...
最近python代码遇到了一个神奇的需求, 就是如果将python utc datetime转换为时间戳. 百度找到都是使用time.mktime(xxx) 但是...calendar.timegm(tuple) 只不过这里需要将 datetime对象调用timetuple()方法才OK哦! 以
Use built-in versions of strptime() and timegm() on all platforms to avoid portability issues. [RT #35183] Fix a bug which could cause a crash when running "rndc reconfig" or "rndc reload" after ...