Saving timestamp in mysql table using php

前端 未结 15 834
既然无缘
既然无缘 2020-12-22 21:44

I have a field in a MySQL table which has a timestamp data type. I am saving data into that table. But when I pass the timestamp (1299762201428) to

15条回答
  •  -上瘾入骨i
    2020-12-22 22:02

    Some things to clarify:

    • MySQL timestamp field type doesn't store unix timestamps but rather a datetime-kind value.
    • UNIX timestamp is a number of a regular int type.
    • The timestamp you're talking about is not a regular unix timestamp but a timestamp with milliseconds.

    therefore the correct answer would be

    $timestamp = '1299762201428';
    $date = date('Y-m-d H:i:s', substr($timestamp, 0, -3));
    

提交回复
热议问题