PHP如何为sitemap.xml lasmod标记设置从MySQL获取的日期的时区
我正在为我发布文章的站点编写php站点地图生成器。我想使用MySQL数据库中的时间戳将其放入sitemap.xml文件的lastmod标记中。代码如下:PHP如何为sitemap.xml lasmod标记设置从MySQL获取的日期的时区,php,mysql,sitemap,utc,dst,Php,Mysql,Sitemap,Utc,Dst,我正在为我发布文章的站点编写php站点地图生成器。我想使用MySQL数据库中的时间戳将其放入sitemap.xml文件的lastmod标记中。代码如下: <?php //request to database: $sql = 'SELECT `id`, `date_update` FROM `table`'; $pdoobj_query = $db->query($sql); $array_db = $pdoobj_query->fetchAll(PDO::FETCH_AS
<?php
//request to database:
$sql = 'SELECT `id`, `date_update` FROM `table`';
$pdoobj_query = $db->query($sql);
$array_db = $pdoobj_query->fetchAll(PDO::FETCH_ASSOC);
date_default_timezone_set('Europe/Moscow');
//generating text of the sitemap.xml
$file = "sitemap.xml";
$sitemap_text = <<<MAP
<?xml version="1.0" encoding="UTF-8"?>
<urlset
xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
MAP;
$number_of_array_elements = count($array_db);
$i=0;
while ($i < $number_of_array_elements){
$sitemap_text .= "\t" . '<url>' . "\r\n";
$sitemap_text .= "\t" . "\t" . '<loc>http://example.com/index.php?page=' . $array_db[$i]['id'] . '</loc>' . "\r\n";
$sitemap_text .= "\t" . "\t" . '<lastmod>' . date('c', strtotime($array_db[$i]['date_update'])) . '</lastmod>' . "\r\n";
$sitemap_text .= "\t" . "\t" . '<changefreq>weekly</changefreq>' . "\r\n";
$sitemap_text .= "\t" . "\t" . '<priority>0.9</priority>' . "\r\n";
$sitemap_text .= "\t" . '</url>' . "\r\n";
$i++;
}
$sitemap_text .='</urlset>';
file_put_contents($file, $sitemap_text);
?>
但php选择了“欧洲/莫斯科”时区,并返回比当前时间提前一小时的2016-02-09T04:41:53+04:00
有没有办法强制php使用UTC+03:00 time zome格式化从MySQL表中提取的时间戳
...
<lastmod>2016-02-06T01:53:44+04:00</lastmod>
...
$original = new DateTime("now");
$timezoneName = timezone_name_from_abbr("", 3*3600, false);
$modified = $original->setTimezone(new DateTimezone($timezoneName));
echo $modified->format('c');