These examples detail the four predefined formats that we can easily
convert dates into:
// get date formatted in RFC 2822
$rfc822 = $date->toRFC822();
// get date formatted in ISO 8601
$iso8601 = $date->toISO8601();
// get date formatted for a MySQL datetime field
$mySQL = $date->toMySQL();
// get date as unix timestamp
$timestamp = $date->toUnix();
You may have noticed that the RFC 2822 method is called toRFC822(). No, it is not a
typo! RFC 2822 replaced RFC 822. The two terms are often used interchangeably and,
unfortunately, it is not unusual to encounter dates and times that use elements from
RFC 822 and RFC 2822. The toRFC822() method actually returns an RFC 2822 date
and time string.
The toMySQL() method is of particular interest if we are using dates and times with
the database. The string that this method returns is suitable for use with a MySQL
database. For more information, please refer to Chapter 3.
If we want to format the date differently, we can use the toFormat() method. To
specify the format we use the same format designators as the PHP strftime()
function.
Pages:
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474