Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re^3: formatting datetime with strftime

by toolic (Chancellor)
on Jul 22, 2013 at 14:55 UTC ( #1045667=note: print w/ replies, xml ) Need Help??


in reply to Re^2: formatting datetime with strftime
in thread formatting datetime with strftime

Show your exact code. It looks like you are using:

$time2 = "%b %d, %y %T"; print "the formatted date time is: $time2 \n";


Comment on Re^3: formatting datetime with strftime
Download Code
Re^4: formatting datetime with strftime
by mreaves (Initiate) on Jul 22, 2013 at 15:21 UTC
    toolic, your hunch is most likely correct, I was using the %T format hoping to get HH:MM:SS. I've since substituted %H:%M:%S and although I don't get an error, I get a bizarre time... I don't think it's UTC or GMT... here's the code:
    #!perl -w use POSIX qw(strftime); use Date::Calc qw(Mktime); $datetimestring = "4/5/13 16:09"; #split datetimestring into date & time ($date_raw, $time_raw) = split(/ /, $datetimestring); print "the date_raw is: $date_raw \n"; #split the date into MM DD YY ($m0_raw, $d0_raw, $y0_raw) = split(/\//, $date_raw); $m_raw = sprintf ("%02d", $m0_raw); print "the m_raw is: $m_raw \n"; $d_raw = sprintf ("%02d", $d0_raw); print "the d_raw is: $d_raw \n"; $y_raw = 2000 + $y0_raw; print "the y_raw is: $y_raw \n\n"; print "the time_raw is: $time_raw \n"; #split the time_raw into HH MM ($hh_raw, $mm_raw) = split(/:/, $time_raw); print "the hh_raw is: $hh_raw \n"; print "the mm_raw is: $mm_raw \n\n"; $s0_raw = 0; $ss_raw = sprintf ("%02d", $s0_raw); #load a Perl datetime variable using mktime $datetime1 = Mktime($y_raw,$m_raw,$d_raw, $hh_raw, $mm_raw, $ss_ra +w); print "the loaded datetime variable is: $datetime1 \n"; #format the datetime variable to match the require format MON dd yyyy +HH:MM:SS GMT $time2 = strftime('%b %d, %y %H:%M:%S', $m_raw, $d0_raw, $y_raw, $ +hh_raw, $mm_raw, $ss_raw); print "the formatted date time is: $time2 \n";
    Here are the results I get:
    the date_raw is: 4/5/13 the m_raw is: 04 the d_raw is: 05 the y_raw is: 2013 the time_raw is: 16:09 the hh_raw is: 16 the mm_raw is: 09 the loaded datetime variable is: 1365192540 the formatted date time is: Jan 07, 01 21:05:04

      The order of your arguments is wrong, it should be
      strftime(fmt, sec, min, hour, mday, mon, year)
      where mon begins at zero and year is since 1900.

      my $datetimestring = "5/4/13 16:09"; my ($month,$day,$year,$hour,$min) = split /\D/,$datetimestring; my $str = strftime("%b %d %Y %H:%M:%S", 0,$min,$hour,$day,$month-1,$y +ear+100);
      poj
Re^4: formatting datetime with strftime
by poj (Curate) on Jul 22, 2013 at 15:34 UTC
    UPDATE : Please Ignore - reply to wrong node

    The order of your arguments is wrong, it should be
    strftime(fmt, sec, min, hour, mday, mon, year)
    where mon begins at zero and year is since 1900.

    my $datetimestring = "5/4/13 16:09"; my ($month,$day,$year,$hour,$min) = split /\D/,$datetimestring; my $str = strftime("%b %d %Y %H:%M:%S", 0,$min,$hour,$day,$month-1,$y +ear+100);
    poj

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (11)
As of 2014-07-11 01:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (217 votes), past polls