abc def
abc def

Reputation: 221

How is date and time stored in the DateTime class in PHP?

I've looked up the DateTime class in the PHP manual page, and I saw that the class has no properties at all. So how is date and time stored inside a DateTime object? How does the __construct() or the setDate() method work, since there's no properties to set?

Upvotes: 0

Views: 105

Answers (1)

Tchoupi
Tchoupi

Reputation: 14691

If you really, really want to know, you can always check read the source code:

https://github.com/php/php-src/blob/master/ext/date/php_date.c

It seems that DateTime contains the UNIX time, and the timezone. Which logically should be enough to handle the time correctly. Now I didn't read the 4258 lines, and I suggest you don't read it (unless it's out of curiosity) and use public methods instead.

Upvotes: 2

Related Questions