dongya9904 2016-05-30 07:19
浏览 32
已采纳

PHP - 将午夜日期转换为时间戳[重复]

This question already has an answer here:

I'm having trouble converting midnight date into timestamp. I'm getting via AJAX POST method timestamp (including time zone offset) from klient, so then I'm converting this to a midnight date like this:

$timestamp = 1463990400; // for example
echo date('d-m-Y H:i:s', strtotime('today', $timestamp));

This line output is: 23-05-2016 00:00:00

And I would love to convert this midnight date time into timestamp to create SQL SELECT.

Is there any solution?

</div>
  • 写回答

1条回答 默认 最新

  • drevls8138 2016-05-30 09:24
    关注

    Finally found way how to solve my problem with mktime() function:

    $offset = date('d-m-Y H:i:s', strtotime('today', $datum_to));
    $parts = preg_split('/\s+/', $offset);
    $date_convert = explode("-", $parts[0]);
    $time_convert = explode(":", $parts[1]);
    
    $this_tz_str = date_default_timezone_get();
    $this_tz = new DateTimeZone($this_tz_str);
    $now = new DateTime("now", $this_tz);
    $offset = $this_tz->getOffset($now);
    
    $second_starttimeUTC = mktime(0, 0, 0, $date_convert[1], $date_convert[0], $date_convert[2])+$offset;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 基于TwinCAT3实现力传感器的实时读取
  • ¥20 python求解八元一次不定方程,无数解中随机输出几组即可(相关搜索:用python)
  • ¥50 libreoffice导出PPTX到PDF中的错误换行问题
  • ¥15 python实现网页视频下载
  • ¥15 如何通过深度图获得物体的完整、正确点云?
  • ¥15 有没有操作系统适用白丁的经典的书籍,如何解决?(标签-学习)
  • ¥15 Catia V5 R20 64位 安装过程中选择orbix配置创建套接字失败
  • ¥100 C51单片机设计交通灯时出现的问题
  • ¥15 R语言爬虫的时候元素和园代码不一样怎么解决呀
  • ¥15 SQL删除添加数据后序号不连续问题。