简体   繁体   English

如何将不同国家语言的日期格式转换为数字日期格式

[英]How to convert date format from different country languages to numeric date format

example例子

26/Veebr/2020 to 26/02/2020 26/Veebr/202026/02/2020

I have a problem to convert date from a different language to dd/mm/yy我在将日期从不同语言转换为dd/mm/yy遇到问题

Like:喜欢:

18/Helmi/2020 to 18/02/2020 18/Helmi/202018/02/2020

With PHP you can created arrays for different languages ​​with elements 'Month Name' => Number.使用 PHP,您可以使用元素 'Month Name' => Number 为不同语言创建数组。 With strtr() the month names are exchanged for numbers.使用 strtr() 将月份名称交换为数字。 The result can then be parsed with DateTime::createFromFormat.然后可以使用 DateTime::createFromFormat 解析结果。

$transEstonian = ['Veebr' => '02'];  //this for all

$strDate = '26/Veebr/2020';

$strDateNum = strtr($strDate,$transEstonian);
$date = DateTime::createFromFormat("d/m/Y H:i",$strDateNum." 00:00");
echo $date->format('Y-m-d');  //2020-02-26

This can be done with javascript similarly.这可以类似地使用 javascript 来完成。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM