开发者

strtotime with year in 2 digit format

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",strtotim开发者_如何学编程e('02-12-2010')) .'<br>'; //02-02-2010
echo date("d-m-Y",strtotime('09.09.2010')) .'<br>'; //09-09-2010

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


strtotime() can be a bit flaky in such cases. It is built to recognize standard american date formats.

If you can use PHP > 5.3, consider using DateCreateFromFormat which has the big advantage of accepting a pre-defined format string to parse the incoming data.

On pre-5.3 platforms, strptime() seems to offer a second-best alternative. It's not available on Windows and has some minor issues - be sure to read the manual page before using.


From the manual:

The "Day, month and two digit year, with dots or tabs" format (dd [.\t] mm "." yy) only works for the year values 61 (inclusive) to 99 (inclusive) - outside those years the time format "HH [.:] MM [.:] SS" has precedence.

You are using '09.09.10' and 10 does not fall in the valid range hence change the separator to -


This is not 2-digit year question. this is non-standard format question.
And asking impossible things from mere a program.
Even me, not being a computer, have no idea what these 09's dooes mean in your date. is it day.month.year? or year.month.day or whatever?
Assuming it's day.month.year:

$list($d,$m,$y) = explode("09.09.10");
echo "$d-$m-20$y";
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜