DD/MM/YYYY的strtotime无法正常工作 [英] strtotime for DD/MM/YYYY not working properly

查看:54
本文介绍了DD/MM/YYYY的strtotime无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从DB '10/09/19'获得了这种类型的日期.今天是今天(2019年9月10日).

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;

这给了我2010-09-19.这表示 2010年9月19日.

It's giving me 2010-09-19. it means 19th Sept 2010.

我希望在 2019年9月10日(2019年9月10日).我已经尝试过SO的许多解决方案,但是没有运气.谁能告诉我我在做什么错吗?

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??

推荐答案

DateTime 类可用于此类情况-它具有有用的方法 createFromFormat

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

这篇关于DD/MM/YYYY的strtotime无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆