转换unix时间戳php

编程入门 行业动态 更新时间:2024-10-10 12:18:34
本文介绍了转换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

本文发布于:2023-05-25 19:53:08,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/236224.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:词库加载错误:Could not find file 'D:\淘小白 高铁采集器win10\Configuration\Dict_Sto

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!