gpt4 book ai didi

php - 将日期从荷兰语转换为英语

转载 作者:塔克拉玛干 更新时间:2023-11-03 05:49:57 26 4
gpt4 key购买 nike

我以为这会很容易,但事实并非如此!我有约会:mei 28, 2015 (dutch) 我想把它转换成英语 Y-m-d

问题是网站是多语言的,所以我希望它保持动态(将 mai 替换为 may)不是解决方案,我已经尝试过:

setlocale(LC_TIME, 'NL_nl');
setlocale(LC_ALL, 'nl_NL');
echo strftime("%Y-%m-%d", strtotime($value));

 $date = date_parse(($value));
print_r($date);

但我总是得到:1970-01-01

有什么想法吗?

我正试图在 magento 中实现这一点,所以也许有 magento 的功能

最佳答案

使用 strptime() 函数 - http://php.net/manual/en/function.strptime.php

$value = 'mei 28, 2015';
$format = '%B %d, %Y';
setlocale(LC_TIME, 'NL_nl');
setlocale(LC_ALL, 'nl_NL');

// get the array with date details
$result = strptime($value, $format);
$day = str_pad($result['tm_mday'] + 1, 2, '0', STR_PAD_LEFT);
$month = str_pad($result['tm_mon'] + 1, 2, '0', STR_PAD_LEFT);
$year = $result['tm_year'] + 1900;

print $year.'-'.$month.'-'.$day;

关于php - 将日期从荷兰语转换为英语,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30261259/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com