简体   繁体   中英

Current_timestamp -> PHP Date()

I have a field in a database labelled "timestamp" that is recording the 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, ie (April 30, 2012 at 3:45pm)

Great resource for this: 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.

use : date("Ymd H:i:s", $current_timestamp);

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

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

请参见有关date函数strtotime函数的文档。

date('F j, Y \a\t g:ia', strtotime( $current_time ));
$time = strtotime($DBDataColumn);
strftime('%a, %b %d %Y at %I:%M %p', $time);

Use the Date object

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM