将datetime转换为timestamp php [英] convert datetime to timestamp php

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

问题描述

我的GPS设备正在与我的php Web服务通信,它发送日期= 311011和时间= 060904格式。

My GPS device is communicating to my php web services, it sends date=311011 and time=060904 formats.

    $time=str_split($time,2);
    $date=str_split($date,2);
    $time=implode(":",$time);
    $date=implode("-",$date);

这给了我所需的日期和时间标准符号。

This gives me the required date and time standard notations.


  • date = 31-10-11

  • time = 06:09:04

现在,我想将此日期,时间转换为时间戳。我使用strtotime(),但日期似乎是31-10-11,这给了奇怪的结果。我必须静静地追加20到11,使其成为2011年,或任何解决方案

Now, i wanna convert this date, time to timestamp. I worked with strtotime(), but the date seems to be 31-10-11, which gives strange results. Do i have to append 20 to 11 statically to make it 2011, or any solution

推荐答案

查看 date fortmats 。如果您使用 - 作为分隔符,则php假定它是 y-mm-dd ,但是您的订单是 dd-mm-y 。最简单的方法是将分隔符更改为然后是$ code> dd.mm.y 。

take a look at the date fortmats. if you use - as separator, php assumes it's y-mm-dd, but your order is dd-mm-y. the easiest way would be to change the separator to . wich would then be dd.mm.y.

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

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