doukongpao0903 2017-04-24 17:58
浏览 72
已采纳

将时间转换为UTC

I know this question has been asked before but somehow I am not able to get this to work in my project so please advise

my php code ( this if else is for checking if time was set or not )

if (isset($_POST['startDate']) && isset($_POST['startTime']))
{
    $date = $_POST['startDate'] . " " . $_POST['startTime'];
    $date = new DateTime($date);
    $date->setTimezone(new DateTimeZone('UTC'));
//    $date = date('Y-m-d H:i:s', $date);

} else
{
    $date = date('Y-m-d H:i:s');
    $date = new DateTime($date);
    $date->setTimezone(new DateTimeZone('UTC'));
}
  • 写回答

1条回答 默认 最新

  • dongliang1873 2017-04-24 18:46
    关注

    Try This::

    <html>
    <head></head>
    <body>   
    
        <form action="#" method="POST">
    
            <input name="startDate" type="date"/>
    
          <br>
    
            <input name="startTime" type="time"/>
    
            <input name="Submit" type="submit" value="Submit" />
        </form>
    
    </body>
    </html>
    
    <?php
    
    if(isset($_POST['Submit'])){
    
    if(isset($_POST['startDate']) && isset($_POST['startTime']))
    {
        $date = $_POST['startDate'] . " " . $_POST['startTime'];
        // $date = "2016-02-01 00:00:01"; Like This..
        
        $date  = new DateTime($date, new DateTimeZone("Asia/Calcutta"));
        $date ->setTimezone(new DateTimeZone("UTC"));
      
      $output = $date ->format("Y-m-d H:i:s"); 
      //echo $output;
    
     $date = new DateTime($output); 
    
    //    $date = date('Y-m-d H:i:s', $date);
    
    } else
    {
        $date ->format("Y-m-d H:i:s"); 
        $date = new DateTime($date, new DateTimeZone("Asia/Calcutta"));
        $date ->setTimezone(new DateTimeZone("UTC"));
    }
    
    
    }
    
    
    ?>

    </div>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 pyqt怎么把滑块和输入框相互绑定,求解决!
  • ¥20 wpf datagrid单元闪烁效果失灵
  • ¥15 券商软件上市公司信息获取问题
  • ¥100 ensp启动设备蓝屏,代码clock_watchdog_timeout
  • ¥15 Android studio AVD启动不了
  • ¥15 陆空双模式无人机怎么做
  • ¥15 想咨询点问题,与算法转换,负荷预测,数字孪生有关
  • ¥15 C#中的编译平台的区别影响
  • ¥15 软件供应链安全是跟可靠性有关还是跟安全性有关?
  • ¥15 电脑蓝屏logfilessrtsrttrail问题