转换unix时间戳php [英] convert unix timestamp php

查看:128
本文介绍了转换unix时间戳php的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个数据库存储我的时间。我使用

  date('Y-m-d H:i:s')从PHP中插入它; 

然后,我使用此函数将其转换为PHP中的unix时间戳

  function convert_datetime($ str)
{
list($ date,$ time)= explode('',$ str);
list($ year,$ month,$ day)= explode(' - ',$ date);
list($ hour,$ minute,$ second)= explode(':',$ time);

$ timestamp = mktime($ hour,$ minute,$ second,$ month,$ day,$ year);

return $ timestamp;
}

我现在需要做的是将此时间戳转换为日期和时间这个格式:
yyyymmddhhmmss(没有任何连字符,破折号,冒号等)。



有没有人有任何想法?

解决方案

您可以使用 strtotime date 函数:回显日期('Ymdhis',strtotime($ date));

  


I have a database that stores the time for me. I insert it from PHP using

date( 'Y-m-d H:i:s');

I then use this function to convert it to a unix timestamp in PHP

function convert_datetime($str) 
{
list($date, $time) = explode(' ', $str);
list($year, $month, $day) = explode('-', $date);
list($hour, $minute, $second) = explode(':', $time);

$timestamp = mktime($hour, $minute, $second, $month, $day, $year);

return $timestamp;
}

What I now need to do is convert this timestamp to the date and time in this format: yyyymmddhhmmss (without any hyphens, dashes, colons, etc).

Has anyone any ideas?

解决方案

You can use the strtotime and date function:

echo date('Ymdhis', strtotime($date));

这篇关于转换unix时间戳php的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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