#!/usr/bin/perl

use strict;

my($year, $month, $mday) = split(/[\.\-]/, shift(@ARGV));
my($hours, $min, $sec, $msec) = split(/[:\.]/, shift(@ARGV));

if (! "$year$month$mday$hours$min$sec$msec") {
	use Time::Local;
	($sec, $min, $hours, $mday, $month, $year) = (localtime)[0, 1, 2, 3, 4, 5];
	$year += 1900;
	$month++;
	$msec = 0;
}

printf("%04d-%02d-%02d %02d:%02d:%02d.%03d\n", $year, $month, $mday, $hours, $min, $sec, $msec);

use Win32::API::Prototype;

my($stime) = pack("S8", $year, $month, 0, $mday, $hours, $min, $sec, $msec);

ApiLink('kernel32.dll', 'BOOL SystemTimeToFileTime(SYSTEMTIME *lpSystemTime, LPFILETIME lpFileTime)')
	|| die "Cannot locate SystemTimeToFileTime()";

my($ftime) = pack("ll",0,0);
if (SystemTimeToFileTime($stime, $ftime)) {
	my($time_l, $time_h) = unpack("ll", $ftime);
	printf("%08x.%08x\n", $time_h, $time_l);
} else {
	printf("Error in SystemTimeToFileTime: %s\n", Win32::FormatMessage(Win32::GetLastError()));
}
