问题
I got this type of date from DB '10/09/19' It's today date(10th sept 2019).
$date = '10/09/19';
//DD/MM/YY
$newdate=date('Y-m-d',strtotime(str_replace('/', '-', $date)));
echo $newdate; //output 2010-09-19
exit;
It's giving me 2010-09-19. it means 19th Sept 2010.
I expect 10-09-2019(10th Sept 2019). I already tried many solutions from SO but no luck. Can anyone tell me what am I doing wrong??
回答1:
The DateTime
class can be used in situations like this - it has the useful method createFromFormat
$date='10/09/19'; //dd/mm/yy
$new=DateTime::createFromFormat('d/m/y', $date )->format('Y/m/d');
echo $new; //2019/09/10
来源:https://stackoverflow.com/questions/57871282/strtotime-for-dd-mm-yyyy-not-working-properly