Is there a way to change Rails default timestamps to Y-m-d H:i:s (instead of Y-m-d H:i:s.u) or have laravel ignore decimal portion of Y-m-d H:i:s.u?

后端 未结 3 456
萌比男神i
萌比男神i 2021-01-25 03:49

I have two applications using the same postgres DB. A laravel application and a rails application. The current data in the DB is in Y-m-d H:i:s format but whenever

3条回答
  •  一个人的身影
    2021-01-25 04:03

    In Laravel/PHP, you can convert DateTime with millisecond to without millisecond using below function:

    $date = date('Y-m-d H:i:s.u');
    echo date('Y-m-d H:i:s', strtotime($date));
    

    In Rails, you can update your time object before sending it to the database, as mentioned below:

    time.change(:usec => 0)
    

提交回复
热议问题