Converting a datetime field timestamp from mysql to php

前端 未结 2 1787
执笔经年
执笔经年 2020-12-12 08:08

I have read about how to do this and most come up with this solution. I just want to display the time format.

$starttime = \"1899-12-30 06:52:47\";


        
相关标签:
2条回答
  • 2020-12-12 08:39

    As mentioned in the comments your date is before the unix epoch. DateTime() allows you to work around that.

    $dt = new DateTime("1899-12-30 06:52:47");
    echo $dt->format("h:i:s");
    
    0 讨论(0)
  • 2020-12-12 08:46
    $starttime = "1899-12-30 06:52:47";
    echo date("h:i:s",strtotime($starttime));
    

    This code works ok for me and displays "06:52:47". It could possibly be because 1899 is before the Unix Epoch (00:00:00 Coordinated Universal Time (UTC), Thursday, 1 January 1970)

    0 讨论(0)
提交回复
热议问题