简体   繁体   中英

Convert Date Time to MySql timestamp

I've set of dates that look like this Sat, 16 Apr 2016 16:29:06 +0000

Who can I convert them to MySql timestamp format using PHP?

$timestamp = $date_time->getTimestamp();

文档: http : //php.net/manual/en/datetime.gettimestamp.php

You can use format method of Datetime

<?php
$date = new DateTime('2000-01-01');
echo $date->format('Y-m-d H:i:s');
?>

output

2000-01-01 00:00:00

Or else you can try date function of PHP

<?php
    $date = "now";//Date in any common format
    echo date("Y-m-d H:i:s",strtotime($date))   
?>

Note* In above example I am using strtotime function to convert string date to PHP timestamp

output

2016-04-20 07:14:46

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