English 中文(简体)
1900年以前安装文件修改时间
原标题:Setting file modification time before the year 1900

我正在创建问题数据集, 我正准备将文件修改时间设定为 & lt; 1900 。 我知道 < a href=" http:// perldoc.perl. org/Time/ local. html" rel= “ nofollow” Time:: 本地 < / a > 使用了1900 的抵消。 我在想, 是否有办法使用此偏移来创建在 1900 年之前修改时间的文件 。 (Windows Enviroment btw.)

这是我至今为止一直使用的代码:

use strict;
use warnings;
use File::stat; 
use Time::localtime;
use Time::Local;

my $file = "test.txt";      
my $when = timelocal(0,0,10,25,6,1899);

#current mod time of the file
my $datetime_string = ctime(stat($file)->mtime);
print $datetime_string,"
";

#change the mod time of the file
utime $when, $when, $file;

#new mod time
$datetime_string = ctime(stat($file)->mtime);
print $datetime_string,"
";

Edit :关于@ikegam s comment,我开始查看 Win32::API 。 具体来说, Win32API:::File:Time 。 这是我至今为止的代码:

use Win32API::File::Time qw{:win};
$filename="AnnotationTest.java";
($atime, $mtime, $ctime) = GetFileTime ($filename);
print $mtime,"
";
SetFileTime ($filename, $atime, $mtime, $ctime);
($atime, $mtime, $ctime) = GetFileTime ($filename);
print $mtime,"
";

使用此代码, 我无法100%确定修改时间的格式 。

问题回答

我不确定是否支持 utime 支持将时间移到那个远处。 如果它是一个从1970年的32位位数的折叠, 那么它只会使您达到1901位数 。 是否在 - ( 2 ** ** 31) 附近有一个截断点?





相关问题
Why does my chdir to a filehandle not work in Perl?

When I try a "chdir" with a filehandle as argument, "chdir" returns 0 and a pwd returns still the same directory. Should that be so? I tried this, because in the documentation to chdir I found: "...

How do I use GetOptions to get the default argument?

I ve read the doc for GetOptions but I can t seem to find what I need... (maybe I am blind) What I want to do is to parse command line like this myperlscript.pl -mode [sth] [inputfile] I can use ...

Object-Oriented Perl constructor syntax and named parameters

I m a little confused about what is going on in Perl constructors. I found these two examples perldoc perlbot. package Foo; #In Perl, the constructor is just a subroutine called new. sub new { #I ...

Where can I find object-oriented Perl tutorials? [closed]

A Google search yields a number of results - but which ones are the best? The Perl site appears to contain two - perlboot and perltoot. I m reading these now, but what else is out there? Note: I ve ...

热门标签