Perl 字符串转换成UNIX时间戳
来源:互联网 发布:mac百度网盘破解限速 编辑:程序博客网 时间:2024/05/18 03:06
最近遇到一个需求,调用perl脚本,由于自己不会perl硬着头皮上
实现的功能是,下一周任一时间发送上一周一周报
#!/usr/bin/perl -w #检测是否是闰年#输入参数年:数值类型#如:2017sub is_leap_year{ my ($year) = @_; my $flag = 0; if((($year) %4 == 0 && ($year) % 100 != 0) || ($year) % 400 == 0){ $flag = 1; }else{ $flag = 0; } return $flag;}#返回偏移后的unix时间戳#参数:年,月,日,偏移日期(可正可负),数值类型#如:2017,9,15,-3,返回2017-9-12-0;00:00的unix时间戳sub getOffsetTimeSecond{ my $ii = 0; my $j = 0 ; my $sec = 0; my ($year,$month,$day,$offsetday) = @_; my @days = (0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); for($ii =1970;$ii < $year; $ii = $ii + 1 ) { my $gg = is_leap_year($ii); my $flag = 1; if($gg == $flag){ $sec += 31622400; }else{ $sec += 31536000; } } for( $j = 1; $j < $month; $j = $j + 1) { my $mm = 2; my $ll = is_leap_year($year); my $flagg = 1; $sec += $days[$j] * 86400; if( $j == $mm && $flagg == $ll) { $sec += 86400; } } $sec += ($day- 1) * 86400; $sec -= 28800; $sec += 86400 * $offsetday; return $sec;} my $txdate;my $jobname;$txdate = $ARGV[2];$jobname = $ARGV[1]; my $y=substr($txdate, 0, 4) + 0;my $m=substr($txdate,4,2) + 0;my $d=substr($txdate,6,2) + 0; my $mysecondtest = getOffsetTimeSecond($y,$m,$d,0);my ($tsec1,$tmin1,$thour1,$tmday1,$tmon1,$tyear_off1,$twday1) = localtime($mysecondtest); if($twday1 == 0){ $twday1 += 7;}my $lastsecond = getOffsetTimeSecond($y,$m,$d,-6-$twday1); my($sec,$min,$hour,$day,$mon,$year) = localtime($lastsecond); $mon++;$year += 1900; $txdate = sprintf("%04d%02d%02d",$year,$mon,$day); #print "$txdate\n"; #发送报表 周报RP_SOHU_AD_WEEKLYmy $code=system("/bin/sh /opt/dwetl/tableau/sh/tableau_mail.sh 'RP_AD_WEEKLY' '$txdate'");exit $code/256;
阅读全文
0 0
- Perl 字符串转换成UNIX时间戳
- python日期时间字符串转换成unix时间戳
- python日期时间字符串转换成unix时间戳
- python日期时间字符串转换成unix时间戳
- unix时间戳转换成java时间
- Java 时间转换成unix时间戳
- perl将字符串时间转换成 epoch time
- php将标准字符串格式时间转换成unix时间戳_strtotime
- unix时间戳转换
- Unix时间戳转换
- unix时间戳转换
- Unix时间戳转换成Date
- unix时间戳转换成指定格式日期的字符串 java
- Unix时间戳(Unix timestamp)转换
- Unix时间戳(Unix timestamp)转换工具
- Unix时间戳(Unix timestamp)转换
- 13/11位unix时间戳转换成标准时间
- unix时间戳转换成标准时间(c#)
- Redis中的StackExchange.redis在C#中的应用
- Android下Shape设置stroke描边部分机型不显示边框线
- 未来,没有什么事是刷脸摆不平的!
- HTTP与HTTPS
- ios react-native 环境配置
- Perl 字符串转换成UNIX时间戳
- 在构建项目的时候如果maven找不到包jconsole,tools两个包
- iOS开发之Runtime常用示例总结
- 基于OpenCV的人脸检测系统
- a+b+c
- ubuntu14.04 安装Kdevelop
- 秋招总结(持续更新)
- Weblogic部署项目三种方式
- 迅为嵌入式4418开发板Android4.4-更改uboot开机LOGO