Thread Perl Skript Datum ändern (11 answers)
Opened by Dani35 at 2011-08-27 14:32

pq
 2011-08-27 17:30
#151867 #151867
User since
2003-08-04
12208 Artikel
Admin1
[Homepage]
user image
also ich würde das mit DateTime machen, da man sich da nicht um sommerzeit u.ä. kümmern muss.
Code (perl): (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
use strict;
use warnings;
use DateTime;
chomp(my $input = <STDIN>);
my ($num, $what) = split " ", $input;
my $now = DateTime->now->set_time_zone("Europe/Berlin");
if ($what =~ m/^min/i) {
    $what = "minutes";
}
elsif ($what =~ m/^st/i) {
    $what = "hours";
}

elsif ($what =~ m/^tag/i) {
    $what = "days";
}
# ...

my $new_date = $now->add( $what => $num );
print "$new_date\n";

eingabe z.B.: -2 tage, 3 stunden, -42 min
Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live. -- Damian Conway in "Perl Best Practices"
lesen: Wiki:Wie frage ich & perlintro Wiki:brian's Leitfaden für jedes Perl-Problem

View full thread Perl Skript Datum ändern