Datetime in PHP Script

后端 未结 3 861
走了就别回头了
走了就别回头了 2020-12-22 02:10

I use a PHP script for a banlist that fetches the date and time, but I have an error and don\'t know how to convert it to \"normal\" time.

It lists me only the date

相关标签:
3条回答
  • 2020-12-22 02:45

    Based on this image (that you have given in deleted answer) you have milliseconds. Divide milliseconds with 1000 to get seconds.

    Probably something like this:

    $datetime = date('d.m.Y \u\m H:i \U\h\r', $row['expires'] / 1000);
    

    But, if you get year 1970, that means that you are on 32bit machine, and your fetched INT is out of range. In this case you could just cut last 3 numbers with string function substr():

    $datetime = date('d.m.Y \u\m H:i \U\h\r', substr($row['expires'], 0, -3));
    
    0 讨论(0)
  • 2020-12-22 02:47

    Convert the date to UNIX timestamp first. Try with -

    $datetime = date("d.m.Y \\u\\m H:i \\U\\h\\r", strtotime($row['expires']));
    echo "<td>$datetime</td>";
    
    0 讨论(0)
  • 2020-12-22 02:50

    It lists me only the date : 01.01.1970 um 00:00 Uhr

    That simply means you are thinking of $row['expires'] incorrectly. That is not a UNIX Timestamp value and is producing an invalid date. It means the value essentially evaluates to 0, which is Jan 1st 1970 in UNIX time

    date() requires you to send a valid Unix timestamp to it (INT 11), is that what you have in database for that field? or it is a date time field?

    Try this

    echo date("d.m.Y \\u\\m H:i \\U\\h\\r", "2014-10-12");   //invalid
    
    echo date("d.m.Y \\u\\m H:i \\U\\h\\r", time());  //valid: current unix timestamp
    
    0 讨论(0)
提交回复
热议问题