嘿,我在为约会的形式而挣扎.我需要调整wordpress项目中某些日期的显示.
Its not a duplicate of 100 I tried the suggestion over there and its not working with that specific date format.
我得到的是D, d. MM yyyy
格式的german date
,看起来像这样:Fr, 6. Mai 2022
我想把它转换成yyyy-mm-dd
=2022-05-06
,但我无法让它工作.我曾try 使用date_parse_from_format和date_create_from_format,但由于德国的月和日名称,它似乎失败了.
$date_german = 'Fr, 6. Mai 2022';
$date_english = 'Fri, 6. May 2022';
print_r(date_create_from_format('D, d. F Y', $date_german)); // doesn't work
print_r(date_create_from_format('D, d. F Y', $date_english)); // works ()
IntlDateFormatter的又一次try
$date = 'Fr, 6. Mai 2022';
$formatter = new IntlDateFormatter("de_DE", IntlDateFormatter::SHORT, IntlDateFormatter::NONE);
$formatter->setPattern('D, d. F Y');
$unixtime=$formatter->parse($date);
$datetime=new DateTime();
$datetime->setTimestamp($unixtime);
echo $datetime->format('Y-m-d');
也不起作用,它返回:1970-01-01
,因为$unixtime是空的?
我还try 在格式化之前将locale设置为de_de,但仍然存在相同的问题.