Sam*_*ton 1 perl timezone http-headers
我正在为新程序员编写一些培训材料,其中我在谈论 HTTP 标头,因此我尝试手动设置 Last-Modified。除了将文件时间设置为格林威治标准时间之外,我已经解决了所有问题。以下是我到目前为止所拥有的:
问题是:给出stat($fh)->mtime可以在任何时区运行的代码,需要添加哪些代码才能转换为GMT?
my $scriptFilename = $ENV{'SCRIPT_FILENAME'};
my $timestamp;
my $fh = FileHandle->new;
if ($fh->open("< ${scriptFilename}")) {
$timestamp = time2str("%a, %e %b %Y %X %Z", stat($fh)->mtime);
$fh->close;
}
#Last-Modified: Tue, 15 Oct 2019 12:45:26 GMT
print <<"END";
Content-type: text/html; charset=iso-8859-1
Last-Modified: $timestamp
<html>
...
</html>
Run Code Online (Sandbox Code Playgroud)
time2str从Date::Format包中(我假设那是time2str从哪里来的)需要一个可选的第三个参数来指定时区。
$timestamp = time2str("%a, %e %b %Y %X %Z", stat($fh)->mtime, 'UTC');
Run Code Online (Sandbox Code Playgroud)