【问题标题】:Data from Timestamp来自时间戳的数据
【发布时间】:2018-04-17 04:11:00
【问题描述】:

我尝试将正确的日期显示为某些特定的时间戳,但每次到第 31 天和最后 3 个时间戳的第 30 天我都会得到不同的日期。

$old_date = date("Y-m-t", $timestamp);

左边可以看到输出,右边是时间戳:

2017-10-31 - 1507326468,
2017-10-31 - 1507409268,
2017-10-31 - 1507492068,
2017-10-31 - 1507574869,
2017-10-31 - 1507657669,
2017-10-31 - 1507740469,
2017-10-31 - 1507823270,
2017-10-31 - 1507906070,
2017-10-31 - 1507988870,
2017-10-31 - 1508071671,
2017-10-31 - 1508154471,
2017-10-31 - 1508237271,
2017-10-31 - 1508320072,
2017-10-31 - 1508402872,
2017-10-31 - 1508485672,
2017-10-31 - 1508568472,
2017-10-31 - 1508651273,
2017-10-31 - 1508734073,
2017-10-31 - 1508816873,
2017-10-31 - 1508899674,
2017-10-31 - 1508982474,
2017-10-31 - 1509065274,
2017-10-31 - 1509148075,
2017-10-31 - 1509230875,
2017-10-31 - 1509313675,
2017-10-31 - 1509396476,
2017-10-31 - 1509479276,
2017-11-30 - 1509562076,
2017-11-30 - 1509644876,
2017-11-30 - 1509727676


编辑: 我必须写:

$old_date = date("Y-m-d", $timestamp);

愚蠢的错误。

【问题讨论】:

  • strtotime('-30 days'); 但最好使用 DateTime 类
  • 谢谢 :) 你回复得很快 :)

标签: php date time timestamp unix-timestamp


【解决方案1】:

您在date("Y-m-t", $timestamp); 中使用的t 代表“给定月份的天数”。 See the manual. 您可能想要使用j,它代表“没有前导零的月份中的某天”。

【讨论】:

  • 哦,我错过了。我想使用d
猜你喜欢
  • 2017-09-29
  • 1970-01-01
  • 2015-12-28
  • 2023-03-27
  • 2011-01-07
  • 1970-01-01
  • 2011-07-12
  • 2019-07-14
  • 2021-06-02
相关资源
最近更新 更多