【问题标题】:Convert database timestamp to date [duplicate]将数据库时间戳转换为日期[重复]
【发布时间】:2016-10-07 01:08:47
【问题描述】:

我有一个格式为2016-06-01 11:46:00 的数据库时间戳,我想将其转换为Wed. 01-06-2016 格式并回显。我尝试了很多,但没有理想的结果。有什么想法吗?

非常感谢,成功了! 如果我想以几天或几周为单位计算今天和过去日期之间的差异,我想我会使用 date_diff。究竟如何?

【问题讨论】:

  • 使用date()函数

标签: php database date timestamp


【解决方案1】:

只需使用datestrtotime

$time = '2016-06-01 11:46:00';
echo date("D. d-m-Y", strtotime($time)); //Wed. 01-06-2016

更新:

$grk = array("Tet"); // complete the rest of the array
$eng = array("Wed"); // complete the rest of the array

$time = '2016-06-01 11:46:00';
$date = date("D. d-m-Y", strtotime($time));
echo str_replace($eng, $grk, $date);

【讨论】:

  • 他需要像星期三一样。 2016 年 1 月 6 日。我认为您需要更新您的解决方案。
  • 当天更新。
  • 要在某一天将D. 更改为其他语言?
  • 什么?我抓不住你。
  • 效果很好!非常感谢!
【解决方案2】:
$time = '2016-06-01 11:46:00';
echo date("D. d-m-Y", strtotime($time)); //Wed. 01-06-2016

【讨论】:

  • 非常感谢。有什么想法可以回显,例如 6 天前?我使用 date_diff,但具体如何?
  • 对于不同的答案,你需要提出另一个问题,你在这里问的很清楚。
  • 我更新了我的问题!没关系,我会的。非常感谢!
猜你喜欢
  • 2014-06-26
  • 2014-09-10
  • 1970-01-01
  • 2014-04-11
  • 2018-09-12
  • 2012-05-15
  • 2012-05-07
  • 1970-01-01
相关资源
最近更新 更多