Current_timestamp -> PHP Date()

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9437438/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 06:49:30  来源:igfitidea点击:

Current_timestamp -> PHP Date()

phpmysqltimestamp

提问by Murphy1976

I have a field in a database labelled "timestamp" that is recording the current_timestamp.

我在数据库中有一个标记为“timestamp”的字段,用于记录 current_timestamp。

What PHP code do I need to write in order to get the current_timestamp (YYYY-MM-DD HH:MM:SS) to display as something a little more reader friendly, i.e. (April 30, 2012 at 3:45pm)

我需要编写什么 PHP 代码才能使 current_timestamp (YYYY-MM-DD HH:MM:SS) 显示为对读者更友好的内容,即(2012 年 4 月 30 日下午 3:45)

回答by Sean Carruthers

Great resource for this: http://php.net/manual/en/function.date.php

很好的资源:http: //php.net/manual/en/function.date.php

$dateTimeVariable = date("F j, Y \a\t g:ia");

This will give you that format of the current time (which seemed to be what you were getting at), otherwise you need to pass the timestamp in after the date format string.

这将为您提供当前时间的格式(这似乎是您所得到的),否则您需要在日期格式字符串之后传递时间戳。

回答by Mouna Cheikhna

use : date("Y-m-d H:i:s", $current_timestamp);

用 : date("Y-m-d H:i:s", $current_timestamp);

or for format like April 30, 2012 at 3:45pm use :

或对于 2012 年 4 月 30 日下午 3:45 之类的格式,请使用:

date('F j, Y at g:ia', $current_timestamp);

回答by Jeff Lambert

See the documentation for the date functionand strtotime function.

请参阅日期函数strtotime 函数的文档。

date('F j, Y \a\t g:ia', strtotime( $current_time ));

回答by Churk

$time = strtotime($DBDataColumn);
strftime('%a, %b %d %Y at %I:%M %p', $time);

回答by Tchoupi

Use the Date object

使用日期对象

$date = DateTime::createFromFormat('Y-m-d H:i:s', $timestamp);
echo $date->format("F t, Y at H:i")