日期时间到Unix时间戳 [英] Datetime To Unix timestamp

查看:104
本文介绍了日期时间到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时间戳的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆