本文介绍了转换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
发布评论