gpt4 book ai didi

转换为 big int 时出现 PHP 日期格式问题

转载 作者:搜寻专家 更新时间:2023-10-31 21:07:16 25 4
gpt4 key购买 nike

我想将 big int 类型的两个日期存储到数据库我有一个序列化的数组并将数组值发送到第二种形式,数组由

[checkin] => 01-07-2015
[checkout] => 03-07-2015

转换后使用

$arr['checkin'] = strtotime($arr['checkin']);
$arr['checkout'] = strtotime($arr['checkout']);

我得到的值分别为 1435689000 1435861800,比实际日期值少一天。

如果我的代码是

<?php echo date('d-m-y', '1435689000');?>

然后输出将是 01-07-15,如果我尝试使用 gmdate 函数如下

echo gmdate('d-m-y', '1435689000');

输出将为 30-06-15

我无法弄清楚问题是什么,请您帮忙。谢谢..

最佳答案

你需要了解这两个函数之间的区别

1) date

string date ( string $format [, int $timestamp = time() ] )

Returns a string formatted according to the given format string using the given integer timestamp or the current time if no timestamp is given. In other words, timestamp is optional and defaults to the value of time().

2) gmdate

string gmdate ( string $format [, int $timestamp = time() ] )

Identical to the date() function except that the time returned is Greenwich Mean Time (GMT).

如果你看过另一个函数,它已经定义了两者是相同的,但是 gmdateGMT

返回

如果你将这两个函数与 time 一起回显,你就会明白其中的区别

echo date('Y-m-d H:i:sP',1435689000);//2015-07-01 00:00:00+05:30

echo gmdate('Y-m-d H:i:sP',1435689000);//2015-06-30 18:30:00+00:00

这是因为根据 GMT 时区,您当前的时间比 GMT+0530。因此两者的输出都是正确的,但不同之处在于时区

关于转换为 big int 时出现 PHP 日期格式问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30431041/

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