gpt4 book ai didi

php - 如何从php中的日期中获取数字?

转载 作者:行者123 更新时间:2023-11-28 23:26:17 26 4
gpt4 key购买 nike

我将日期以 varchar 格式存储在数据库中。我想从输入日期中获取 8 位数字。输入日期可以是任何格式,如 28/08/2016 、 28-08-2016 或 28 Aug 2016 等。

现在我试着这样做:

    $country = mb_substr($this->country, 0, 4);
$username = $this->user_name;
$converted_date = date('Y_m_d-H-i-s', strtotime($this->date_of_application));
$this-> member_id = $country.$username.$converted_date;

我正在连接字符串和日期。所以我的输入日期是:28/08/2016,我得到的输出是:1970_01_01-04-00-00

我更改了 php.ini 文件中的时区。

所以我想要输出为数字 28082016。我怎样才能得到这个?

最佳答案

'Y_m_d-H-i-s' 是日期的格式。因此,如果您想将日期连接到 28082016,应该这样做:

$converted_date = date('dmY', strtotime($this->date_of_application));

关于php - 如何从php中的日期中获取数字?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39207183/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com