strtotime with year in 2 digit format

sat*_*tya 3 php

Hallo can someone explain the behaviour of strtotime function with year in non-standard format.

echo date("d-m-Y",strtotime('02-12-10')) .'<br>'; //10-12-2002
echo date("d-m-Y",strtotime('09.09.10')) .'<br>'; //02-09-2010 --How this is interpreted?


echo date("d-m-Y",strtotime('02-12-2010')) .'<br>'; //02-02-2010
echo date("d-m-Y",strtotime('09.09.2010')) .'<br>'; //09-09-2010
Run Code Online (Sandbox Code Playgroud)

I wanted to convert strings of format dd.mm.yy(09.09.10) to datetime format.

Pek*_*ica 6

strtotime()在这种情况下可能有点不稳定.它旨在识别标准的美国日期格式.

如果您可以使用PHP> 5.3,请考虑使用DateCreateFromFormat,它具有接受预定义格式字符串来解析传入数据的巨大优势.

在5.3之前的平台上,strptime()似乎提供了第二好的选择.它在Windows上不可用,并且有一些小问题 - 请务必在使用前阅读手册页.

  • @hopeseekr定义"标准".在我的祖国德国,"09.09.10"是一种有效的格式,意思是2010年9月9日.什么反对将此转换 - 例如从用户输入 - 转换为时间戳*直接*,而不是使用繁琐的字符串操作使其成为ISO日期第一?对我毫无意义. (3认同)