简体   繁体   中英

How to convert date to timestamp in PHP?

How do I get timestamp from eg 22-09-2008 ?

如何从例如22-09-2008获取时间戳?

如何从例如22-09-2008获取时间戳?

如何从例如22-09-2008获取时间戳?

如何从例如22-09-2008获取时间戳?

如何从例如22-09-2008获取时间戳?

如何从例如22-09-2008获取时间戳?

如何从例如22-09-2008获取时间戳?

如何从例如22-09-2008获取时间戳?

如何从例如22-09-2008获取时间戳?

如何从例如22-09-2008获取时间戳?

如何从例如22-09-2008获取时间戳?

如何从例如22-09-2008获取时间戳?

如何从例如22-09-2008获取时间戳?

如何从例如22-09-2008获取时间戳?

如何从例如22-09-2008获取时间戳?

如何从例如22-09-2008获取时间戳?

如何从例如22-09-2008获取时间戳?

如何从例如22-09-2008获取时间戳?

For PHP >=5.3, 7 & 8 the this may work-

$date = date_parse_from_format('%Y-%m-%d', "2022-11-15"); //here you can give your desired date in desired format. 
                                                           //just need to keep in mind that date and format matches.

$timestamp = mktime(0, 0, 0, $date['month'], $date['day'], $date['year'] + 2000); //this will return the timestamp

$finalDate= date('Y-m-d H:i:s', $timestamp); //now you can convert your timestamp to desired dateTime format.

If you already have the date in that format, you only need to call the " strtotime " function in PHP.

$date = '22-09-2008';
$timestamp = strtotime($date);
echo $timestamp; // 1222041600

Or in a single line:

echo strtotime('22-09-2008');

Short and simple.

I have used this format: $presentDateTime = strtotime(date('Ymd H:i:s'));

如何从例如22-09-2008获取时间戳?

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