Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: Converting Active Directory date Time to something useful

by astroboy (Chaplain)
on Oct 21, 2014 at 00:59 UTC ( [id://1104505]=note: print w/replies, xml ) Need Help??


in reply to Converting Active Directory date Time to something useful

In case someone else is researching this, I've put down a solution that I've cobbled from http://code.activestate.com/lists/perl-win32-users/10905/. I use DateTime objects for my date in my app, so I've pulled the relevant bits out:
use DateTime; use DateTime::Format::Epoch; # Windows epochs start on 1 Jan 1601 my $base_dt = DateTime->new( year => 1601, month => 1, day => 1 ); my $formatter = DateTime::Format::Epoch->new( epoch => $base_dt, unit => 'seconds', type => 'int', # or 'float', 'bigint' skip_leap_seconds => 1, start_at => 0, local_epoch => undef, ); # $value contains the Win32:OLE date my $hi_val = $value->HighPart; my $low_val = $value->LowPart; my $factor = 10000000; my $unp_val = pack("II", $low_val, $hi_val); my ($bVp, $aVp) = unpack("LL", $unp_val); $unp_val = ($aVp * 2**32 + $bVp) / $factor; if ($unp_val != 0) { my $dt = $formatter->parse_datetime($unp_val); # Good habit - always explicitly set to UTC zone before # converting to the local zone $dt->set_time_zone('UTC'); $dt->set_time_zone('local'); print $dt->strftime('%Y-%m-%d %H:%M:%S'); }

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (3)
As of 2024-04-25 20:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found