Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re^3: Converting POSIX format date/times to epoch seconds

by Anonymous Monk
on Oct 09, 2014 at 15:53 UTC ( [id://1103313]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Converting POSIX format date/times to epoch seconds
in thread Converting POSIX format date/times to epoch seconds

I needed to convert the date from the WMIC command output so I added a block to the code (using a copy anyway for other reasons). it is small enough to customize and here is a small customization (which can probably be improved). I wanted to have a "better" way of determining up time - converting the boot time then taking the delta seemed to be a simple solution. FYI - Win32::GetTickCount was returning 13 days (in ms) on my machine which has been up for 150something days. using this change and time() function to get a delta produced a correct result.

# WMIC (Windows command line) Date output format from `wmic os get + lastbootuptime` (($yr, $mon, $day, $hr, $min, $sec) = /^ (\d{4}) # year (\d\d) # numerical month (\d\d) # day (\d\d) # Hour (\d\d) # Min (\d\d) # Sec /x) ||

Replies are listed 'Best First'.
Re^4: Converting POSIX format date/times to epoch seconds
by Anonymous Monk on Oct 21, 2014 at 15:31 UTC

    for those who come here looking for the boot time, here is a program to convert the wmic format boot time to seconds then redisplay it. I cloned the HTTP::Date code then chopped it down to this. also being posted on http://www.perlmonks.org/?node_id=216892

    use strict; use Time::Local; sub wmic2time (;$) { my $wmic_time_in=$_[0]; if(!defined $wmic_time_in) { $wmic_time_in=join " ",`wmic os get lastbootuptime 2>&1`; $wmic_time_in=~s/\r\n/ /g; $wmic_time_in=~s/ * / /g; } $wmic_time_in=~s/LastBootUpTime //i; # caller may have remove +d this already but just in case.... my @d = $wmic_time_in =~ /^(\d{4})(\d\d)(\d\d)(\d\d)(\d\d)(\d\d)/x +; # year numerical month day Hour Min Sec return undef unless @d; $d[1]--; # month return eval { my $t = Time::Local::timelocal(reverse @d); $t < 0 ? undef : $t; }; } my $newtime=wmic2time; print "$newtime\n"; print scalar localtime $newtime . "\n";

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (6)
As of 2024-04-23 09:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found