Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Is there a shorter way to create a german time string?

by neophyte (Curate)
on Sep 26, 2000 at 14:41 UTC ( #33994=perlquestion: print w/replies, xml ) Need Help??

neophyte has asked for the wisdom of the Perl Monks concerning the following question: (dates and times)

This is the code I have been using for a while:
sub zeit { my $wtag = ("Sonntag", "Montag", "Dienstag", "Mittwoch", "Donnerstag", + "Freitag", "Samstag")[(localtime)[6]]; my $mtag = sprintf("%02d", (localtime)[3]); my $monat = ("Januar"," Februar", "Maerz", "April"," Mai", "Juni", "Ju +li", "August", "September", "Oktober", "November", "Dezember")[(local +time)[4]]; my $jahr = (localtime)[5] + 1900; my $stunde = sprintf("%02d", (localtime)[2]); my $min = sprintf("%02d", (localtime)[1]); my $zeit = "$wtag, den $mtag\. $monat $jahr um $stunde\:$min Uhr"; return $zeit; }

It works fine for me, but I just wondered.

Originally posted as a Categorized Question.

Replies are listed 'Best First'.
Re: Is there a shorter way to create a german time string?
by t0mas (Priest) on Sep 26, 2000 at 15:10 UTC
    How about:
    use Date::Manip; $ENV{TZ}="CET"; &Date_Init( "Language=German" ); print &UnixDate( "heute", "%A, den %m. %B %Y um %H:%M Uhr" );
    /brother t0mas
      This is very concise. And if I had to do more date-parsing than just for this one string I would install Date::Manip. But as the review states: this module might be an overkill. So for now I'll be using my lengthy sub.
       
      Thank you anyway for leading my attention to a module I hadn't known before.
       
      neophyte
Re: Is there a shorter way to create a german time string?
by Fastolfe (Vicar) on Nov 20, 2000 at 19:18 UTC
    If you're familiar with POSIX's strftime function, you can use Perl's locale features to modify strftime's behavior, depending upon the current locale.
    use POSIX qw(locale_h setlocale strftime); setlocale(LC_TIME, "de"); $de_time = strftime(...);

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://33994]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (2)
As of 2022-08-16 21:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?