如何解决未与服务器 bash 语言同步的 php strtotime 语言问题

How to solve a php strtotime language issue not sincronyzed with server bash language

我有一台服务器 运行 为 Bash 设置德语本地语言。当我尝试更改邮件日志时间时 在此服务器中使用 ..

的 Unix 时间戳
$time1="Mai-05-20 17:22:36";
$unix_time=strtotime($time1);

$unix_time returns 是空的,我想是因为 bash 使用的是德语,而 PHP 是 运行ning 英语 (?).

如何将 php 脚本设置为 运行 与 Bash 本地语言相同的语言?

来自 docs(强调我的):

strtotime — Parse about any English textual datetime description into a Unix timestamp

如果您不需要 strtotime() 的全部功能(毕竟,您似乎是从一个程序中解析日志),您可以尝试 IntlDateFormatter::parse(). Here's a quick and dirty demo:

$fmt = new IntlDateFormatter('de_DE', null, null);
$fmt->setPattern('M-dd-yy hh:mm:ss');
$log_time = "Mai-05-20 17:22:36";
$unix_time = $fmt->parse($log_time);
echo date('r', $unix_time);

Tue, 05 May 2020 17:22:36 +0200

请注意,Unix 时间是固定时间,因此不受时区影响。我在转换为当地时间时得到 +0200,因为我的 PHP default time zone 当前是 CEST。