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.
strtotime()在这种情况下可能有点不稳定.它旨在识别标准的美国日期格式.
如果您可以使用PHP> 5.3,请考虑使用DateCreateFromFormat,它具有接受预定义格式字符串来解析传入数据的巨大优势.
在5.3之前的平台上,strptime()似乎提供了第二好的选择.它在Windows上不可用,并且有一些小问题 - 请务必在使用前阅读手册页.