Set time in perl
来源:百度文库 编辑:神马文学网 时间:2024/06/03 06:34:44
use strict;
use Time::Local;
use Win32::API;
my $GetSystemTime;
my $SetSystemTime;
my @time = getTime (); # get the system time
my $ret = setTime (@time); # set the time back to the same time for test
exit;
#- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
sub getTime {
if (not $GetSystemTime) {
$GetSystemTime = new Win32::API(‘Kernel32.dll‘, ‘GetSystemTime‘, ‘P‘,
‘V‘) or die "Get GetSystemTime: $! ($^E)";
}
# 8 short words: year month wday mday hr min sec msec
my $lpSystemTime = pack ‘SSSSSSSS‘, 0 x 8;
$GetSystemTime-> Call($lpSystemTime);
my @t = unpack ‘SSSSSSSS‘, $lpSystemTime;
printf "Current UT: %04u%02u%02u %02u:%02u:%02u.%03u\n", $t[0], $t[1], $t[3],
$t[4], $t[5], $t[6], $t[7] if $debug;
return @t;
}
#- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
sub setTime {
my @t = @_;
my $SetSystemTime = new Win32::API(‘Kernel32.dll‘, ‘SetSystemTime‘, ‘P‘, ‘I‘)
or die "Get SetSystemTime: $! ($^E)"
# 8 short words: year month wday mday hr min sec msec
my $lpSystemTime = pack ‘SSSSSSSS‘, $t[5]+1900, $t[4]+1, 0, $t[3], $t[2],
$t[1], $t[0], 500; # wday not used and msec not avail so use half
my $ret = $SetSystemTime-> Call($lpSystemTime);
print "SetSystemTime ret=$ret\n" if $debug;
return $ret;
}
#- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
__END__
use Time::Local;
use Win32::API;
my $GetSystemTime;
my $SetSystemTime;
my @time = getTime (); # get the system time
my $ret = setTime (@time); # set the time back to the same time for test
exit;
#- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
sub getTime {
if (not $GetSystemTime) {
$GetSystemTime = new Win32::API(‘Kernel32.dll‘, ‘GetSystemTime‘, ‘P‘,
‘V‘) or die "Get GetSystemTime: $! ($^E)";
}
# 8 short words: year month wday mday hr min sec msec
my $lpSystemTime = pack ‘SSSSSSSS‘, 0 x 8;
$GetSystemTime-> Call($lpSystemTime);
my @t = unpack ‘SSSSSSSS‘, $lpSystemTime;
printf "Current UT: %04u%02u%02u %02u:%02u:%02u.%03u\n", $t[0], $t[1], $t[3],
$t[4], $t[5], $t[6], $t[7] if $debug;
return @t;
}
#- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
sub setTime {
my @t = @_;
my $SetSystemTime = new Win32::API(‘Kernel32.dll‘, ‘SetSystemTime‘, ‘P‘, ‘I‘)
or die "Get SetSystemTime: $! ($^E)"
# 8 short words: year month wday mday hr min sec msec
my $lpSystemTime = pack ‘SSSSSSSS‘, $t[5]+1900, $t[4]+1, 0, $t[3], $t[2],
$t[1], $t[0], 500; # wday not used and msec not avail so use half
my $ret = $SetSystemTime-> Call($lpSystemTime);
print "SetSystemTime ret=$ret\n" if $debug;
return $ret;
}
#- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
__END__
Set time in perl
Socket Programming in PERL
perl
perl
Number of US students set to soar in 4 years
Population set to hit 100 million in Henan
Jewish settlers set fire to olive farms in West Bank
Blacks Set Out in Search of a Better Life in 1920s American Society
Peru vs Fujimori: justice in the time of reas...
雅尼音乐:第七张专辑In My Time
15 state organs fail to reveal reports in due time
FIFA.com - Uruguay back in the big time
TIME
time
Whitebox makers in China reportedly set to launch ARM-based netbooks
Turn Your Dream Into Reality in 5 Minutes a Day:Tips for Time-Stressed Dreamers
Better in time《一切都会好起来》痊愈的同时也会痛
win32 programmer directx video How to reset start time in renderer?
Once In A Life Time - 日志 - 把你放在心上 - 爱词霸E社会
Checkpoint tuning: how to find the bottlenecks in the checkpoint duration time(Technote)
Perl 工具
Perl概述
Perl 教程
Perl 教程