【发布时间】:2020-05-15 10:57:41
【问题描述】:
我正在抓取一个博客站点,到目前为止一切正常,但是现在博客站点已更改为多语言,现在我在抓取日期和时间时遇到了问题。所以帮我解决这个问题。
之前我曾经通过不同的方式从博客站点获取日期格式,如下所示。
Thursday, 31 October 2019
Thursday, September 10, 2020
这对我来说很好,因为我可以通过以下方式转换为 PHP。
$fetched_date = $info['date']; // which is 'Thursday, 31 October 2019'
$time_stamp = strtotime($fetched_date);
$new_date = date('Y-m-d', $time_stamp);
// It was gave me this date '2019-10-31',
// which is perfect for me, because i can store it to my DB.
但由于博客网站已更改为多语言,我偶尔会得到以下另一种语言的日期。那么如何转换呢?
गुरुवार, १८ जून, २०२० // mr_IN
ગુરુવાર, 10 સપ્ટેમ્બર, 2020 // gu_IN
所以当我尝试使用这种日期格式时,它给了我错误的日期,我什至无法使用。喜欢,
$fetched_date = $info['date']; // which is 'गुरुवार, १८ जून, २०२०'
$time_stamp = strtotime($fetched_date);
$new_date = date('Y-m-d', $time_stamp);
// It was gave me this date '1970-01-01', which is wrong and i can't store to my DB.
// it should be "2020-06-18"
当我进行抓取时,我还会得到一个语言代码,例如:mr_IN、gu_IN,那么如何使用该语言代码获得正确的日期?
我想在 PHP 中转换日期并将其存储在 MySQL 中,我该怎么做?
【问题讨论】:
标签: php date web-scraping country-codes