php - DateTime returns wrong year -


my code following:

<?php $newdate = new datetime('2012'); echo $newdate->format('y'); 

why $newdate->format('y') returns 2015 (current year) , not 2012?

because 2012 not valid date string. default date , time set object current, 2015. can hint format going use datetime::createfromformat

$date = datetime::createfromformat('y', '2012'); echo $date->format('y'); 

Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -