Sorry ,
saya pakai perl yang di DOS/WIN versi 5.004_02
dan Packagenya "Date::DateCalc"
beda kali... antara perl WIN32 dan UNIX ....
Zakaria wrote:
>
> Assalamualaikum wr. wb.
>
> P11 wrote:
> > Kalo aku pake Package "Date::DateCalc"
> >
> > #!perl -w
> > use Date::DateCalc qw(date_time_difference);
> >
> > ($days,$hh,$mm,$ss) = date_time_difference
> > (
> > $year1,$month1,$day1,$hh1,$mm1,$ss1,
> > $year2,$month2,$day2,$hh2,$mm2,$ss2
> > );
> >
> > tinggal conversi aja outputnya ke menit.....
> >
> > Zakaria wrote:
> [sensor]
> > > Bagaimana caranya menghitung selisih antara dua string tanggal
> > > hasil output `date` sehingga menghasilkan menit?
>
> Terimakasih atas informasinya dan sedikit koreksi waktu saya cari
> di CPAN http://www.perl.com/CPAN/ modulenya yang ada adalah Date::Calc
> dan functionnya namanya Delta_DHMS.
>
> Berikut script perl untuk mengubah dari file log:
> --------------------------------------------------------
> Connection to CBN started: Wed Feb 23 17:03:33 JAVT 2000
> By prayudy
> Stop: Wed Feb 23 17:18:47 JAVT 2000
> Connection to CBN started: Wed Feb 23 17:35:22 JAVT 2000
> By herman
> Stop: Wed Feb 23 17:49:29 JAVT 2000
> Connection to CBN started: Wed Feb 23 18:00:38 JAVT 2000
> By root
> Stop: Wed Feb 23 18:24:44 JAVT 2000
> Connection to CBN started: Wed Feb 23 20:46:10 JAVT 2000
> By wisnu
> Stop: Wed Feb 23 21:03:37 JAVT 2000
> --------------------------------------------------------
>
> Menjadi tab separated:
> ---------------------------------------
> user ISP mulai selesai minutes
> prayudy CBN 2000-2-23 17:03:33 2000-2-23 17:18:47 15
> herman CBN 2000-2-23 17:35:22 2000-2-23 17:49:29 14
> root CBN 2000-2-23 18:00:38 2000-2-23 18:24:44 24
> wisnu CBN 2000-2-23 20:46:10 2000-2-23 21:03:37 17
> ---------------------------------------
>
> Source:
> --------------------------------------------------------
> #!/usr/bin/perl -w
> # Program to analize ppp-log file that has a format like this
> # Connection to CBN started: Thu Feb 24 10:08:40 JAVT 2000
> # By zakaria
> # Stop: Thu Feb 24 10:15:56 JAVT 2000
>
> use Date::Calc qw(:all);
>
> $status=1;
> print "user\tISP\tmulai\tselesai\tminutes\n";
> while ( <STDIN> ) {
> if ($status == 1 && /^Connection to (\S+) started: (.*)$/ ) {
> $isp = $1;
> $start = $2;
> $status = 2;
> } elsif ($status == 2 && /^By (.*)$/ ) {
> $who = $1;
> $status = 3;
> } elsif ($status == 3 && /^Stop: (.*)$/ ) {
> $end = $1;
> @st = ($s_year, $s_month, $s_day, $s_hour, $s_min, $s_sec)
> = parse_date($start);
> @end = ($e_year, $e_month, $e_day, $e_hour, $e_min, $e_sec)
> = parse_date($end);
> $num = num_minutes( @st, @end );
> print "$who\t$isp\t$s_year-$s_month-$s_day $s_hour:$s_min:$s_sec\t"
> .
> "$e_year-$e_month-$e_day $e_hour:$e_min:$e_sec\t$num\n" ;
> $status = 1;
> } else {
> print STDERR "Log format error:\n$. : ($status) $_";
> }
> }
>
> # Subtrack two values and return minutes
> sub num_minutes {
> my ($days, $hh, $mm) = Delta_DHMS (@_);
> return $mm + ($hh * 60) + ($days * 24 * 60);
> }
>
> # Convert string date "Thu Feb 24 12:01:40 JAVT 2000" to
> # (year, month, date, hour, minutes, second)
> sub parse_date {
> ($date) = @_;
> my($month, $day, $time, $year) = (split (/\s+/, $date) ) [1..3,5];
> my($hh, $mm, $ss) = split /:/, $time;
> $month = Decode_Month($month);
> return ($year, $month, $day, $hh, $mm, $ss);
> }
> --------------------------------------------------------
>
> Wassallam,
>
> -- Zakaria
>
> PT. Asia Karsa Indah [EMAIL PROTECTED]
> Advanced Technologies [EMAIL PROTECTED]
> Jl. Raya Kalimalang 4B, Jakarta [EMAIL PROTECTED]
> Telp : (62-21) 8649318 http://www.asia-karsa.com
> Fax : (62-21) 8649316 http://linux.or.id/pemula
>
> --------------------------------------------------------------------------------
> Utk berhenti langganan, kirim email ke [EMAIL PROTECTED]
> Informasi arsip di http://www.linux.or.id/milis.php3
> Pengelola dapat dihubungi lewat [EMAIL PROTECTED]
--------------------------------------------------------------------------------
Utk berhenti langganan, kirim email ke [EMAIL PROTECTED]
Informasi arsip di http://www.linux.or.id/milis.php3
Pengelola dapat dihubungi lewat [EMAIL PROTECTED]