Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2147768
  • 博文数量: 227
  • 博客积分: 10521
  • 博客等级: 上将
  • 技术积分: 3452
  • 用 户 组: 普通用户
  • 注册时间: 2006-10-20 14:59
个人简介

低调做人,高调做事!

文章分类

全部博文(227)

文章存档

2013年(4)

2012年(8)

2011年(16)

2010年(24)

2009年(92)

2008年(83)

分类: LINUX

2008-11-06 18:16:56

1,比较2个日期相差的时间

use strict;
use Date::Manip;

my $now_time = time();
print $now_time . "\n";

my $now_time_1 = localtime();
print $now_time_1 . "\n";

my $now_time_2 = gmtime();
print $now_time_2 . "\n";


my $old_seconds = UnixDate("3 Nov 2008 15:30:02", "%s");
my $new_seconds = UnixDate("$now_time_1", "%s");

print $old_seconds . "\n";
print $new_seconds . "\n";

my $difference_in_seconds = $new_seconds - $old_seconds;

print $difference_in_seconds . "\n";
print "\n";

my $difference_in_minutes = $difference_in_seconds / 60;
my $difference_in_hours = $difference_in_seconds / 3600;
my $difference_in_days = $difference_in_seconds / 86400;

print $difference_in_minutes . "\n";;
print $difference_in_hours . "\n";;
print $difference_in_days . "\n";;

if ($difference_in_days < 3) {
        print "less than 3 days, not send mail" . "\n";
} else {
        print  "than 3 days, send mail ok" . "\n";
}




2,比较2个日期的早晚


#!/usr/bin/perl -w

use strict;
use Date::Manip;

my $now_time_1 = localtime();
my $old_seconds = UnixDate("$now_time_1", "[%Y-%m-%d_%H:%M:%S]");
print $old_seconds . "\n";

my $date1 = "$now_time_1";
my $date2 = "2008/05/06";
my $flag = Date_Cmp($date1, $date2);

if($flag < 0) {
        print "date1 is earlier!\n";
}
elsif($flag == 0) {
        print "the two dates are identical!\n";
}
else {
        print "date2 is earlier!\n";
}



3,判断是否是符合的日志格式


#!/usr/bin/perl -w

use strict;
use Date::Manip;

my $date = ParseDate("2008");

print $date . "\n";

if (! $date) {
   print  "Error in the date" . "\n";
} else {
   print "in the date" . "\n";
}



4,简单的应用

#!/usr/bin/perl

use strict;
use warnings;

my ( $s, $m, $h, $d, $M,, $y ) = localtime(time);
print "sec  is: $s\n";
print "min  is: $m\n";
print "hour is: $h\n";
print "day  is: $d\n";
$M = $M + 1;
print "mon  is: $M\n";
$y = $y + 1900;
print "year is: $y\n";
阅读(1801) | 评论(0) | 转发(1) |
给主人留下些什么吧!~~