#47: Formatting Dates and Times
Because humans don't understand timestamps very well, whenever you want to print a date, you should use a format such as Oct 15, 2008.
We already touched on the date() function earlier in this chapter; now let's look at how it works. Its two parameters are a date format (such as 'M j, Y') and a timestamp, and the return value is a string. For example, date('M j, Y', 1151884800) yields Jul 2, 2006 in Pacific Standard Time. If you omit the timestamp parameter, date() uses the current time.
The date format can have extra characters, such as colons and commas, but unlike other functions that take a format—such as printf()—you must be especially careful not to use reserved formatting characters because there is no format ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access