PHP日期转换为strtotime [英] PHP date conversion to strtotime

查看:108
本文介绍了PHP日期转换为strtotime的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个数组,其中每个记录都有一个'date'字段。日期格式如下: '10 / 09/2015'。当我在这些日期使用 strtotime 时,其中一些以 false 出现。我以为在数据结构中有一个错误,所以我创建了这个简单的数组和一个简单的 foreach 循环,他们输出在某些情况下, false 什么不喜欢?

I have an array where each record has a 'date' field. The dates are in this format: '10/09/2015'. When I use strtotime on these dates, some of them come out as false. I thought there was a mistake in data structure so I created this simple array and a simple foreach loop, and they output false in some cases. What does it not like?

$dates = [];

$someData = [
    '21/05/2014',
    '22/05/2014',
    '09/06/2014',
    '04/07/2014',
];

foreach($someData as $date) {
    $dates[] = strtotime($date);
}

print_r($dates);die;


推荐答案

你需要了解你的日期格式日期。
这里 m / d / Y 被认为是标准的美国日期格式。

You need to understand over here the date format of your date. Here m/d/Y is considered to be the standard American Date format.

所以当你的日期就像

'09/06/2014',//it should be considered as 06 september 2014
'04/07/2014',//it should be considered as 07 april 2014

日期就像

'21/05/2014',
'22/05/2014',

然后,上述日期不符合美国日期格式的标准,即 m / d / Y 而不是你可以做的是将 / - 将您的日期转换为欧洲日期格式,即 dmY

Then the above date doesn't fits within the standards of American Date Format i.e. m/d/Y instead what you can do over here is replace / along with - which converts your date into European Date Format which is d-m-Y

这篇关于PHP日期转换为strtotime的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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