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;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序
  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 Centos / PETSc / PETGEM