3

I have a web API and locally the datetime object is serialized like this:

"timeInsert":{"date":"2014-12-09 01:15:19","timezone_type":3,"timezone":"Europe\/Ljubljana"}

When I deploy the application online on a server, the datetime is serialized like this:

"timeInsert":{"date":"2014-12-09 01:15:19.000000","timezone_type":3,"timezone":"Europe\/Ljubljana"}

Note the appended .000000 (microseconds). Both servers (local inside Vagrant and live) run on Linux Ubuntu 12.04.

Date command on both servers outputs the same: Mon Dec 22 08:20:28 UTC 2014 and both have PHP version 5.5.x (x differs a little bit).

What could be the reason the datetime is serialized different on both systems? I would like the date without microseconds. Thanks in advance!:)

4
  • 1
    It's not the php serialization format. What do you mean by 'serialized'? Commented Dec 22, 2014 at 8:29
  • I use json_encode on the datetime object. I can manually get the desired format with format method, but I really wonder why the same code on mostly the same systems outputs different at the moment. Commented Dec 22, 2014 at 8:30
  • It dependences on PHP version: 3v4l.org/pKPcJ Commented Dec 22, 2014 at 8:33
  • Thank you sectus, that is exactly what I needed. The php version is exactly what looks like is causing the problem. You can write an answer so I an accept it:) Commented Dec 22, 2014 at 8:34

1 Answer 1

4

This behavior dependencies on PHP version and relayed on PHP bug: #67308 Serialize of DateTime truncates fractions of second - https://github.com/php/php-src/blob/PHP-5.6.4/NEWS#L902

Simple script to check

echo  json_encode(new DateTime('@1419237113'));

http://3v4l.org/pKPcJ

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.