Mecha CMS

Date and time.

$date->pattern()

Format date input using custom formatter.

2.2.0
$date->pattern(string $pattern = '%Y%-%M%-%D% %~h%:%m%:%s%');

Example:

$date = (new Date('2019-06-25 15:47:32'))->pattern('%Y%/%M%/%D%');

Result:

$date = '2019/06/25';

Supported date pattern:

PatternDescription
%Y%Get year number.
%M%Get month number (from 01 to 12).
%D%Get day number (from 01 to 31).
%h%Get hour 12 number (from 00 to 12).
%m%Get minute number (from 00 to 60).
%s%Get second number (from 00 to 60).
%N%AM or PM.
%W%Get day number in a week (from 01 to 07).
%Z%Get current time zone.
%~M%Get month name.
%~D%Get day name.
%~h%Get hour 24 number (from 00 to 24).