沃梦达 / 编程问答 / php问题 / 正文

日期时间到 Unix 时间戳

Datetime To Unix timestamp(日期时间到 Unix 时间戳)

本文介绍了日期时间到 Unix 时间戳的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有人使用 PHP 函数将格式为 0000-00-00 00:00:00(datetimesql) 的日期转换为 unix 时间戳?

Is there anyone sitting on a PHP function to convert a date of format 0000-00-00 00:00:00(datetimesql) to unix timestamp?

推荐答案

要在 PHP 5.2 中执行此操作,您可以这样做:

To do this in PHP 5.2 you can do this:

$datetime = new DateTime();
echo $datetime->format('U');

从 PHP 5.3 开始,一种更新的方法是:

A newer way to do this as of PHP 5.3 is:

$datetime = new DateTime();
echo $datetime->getTimestamp();

这篇关于日期时间到 Unix 时间戳的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:日期时间到 Unix 时间戳

基础教程推荐