About Chronos (DateTime)

Windwalker\Core\DateTime\Chronos is sub class of PHP DateTime. This class is based on Joomla JDate and add some new features.

All PHP DateTime functions are able to use on Windwalker Chronos, see PHP DateTime


Chronos supports Timezone as string.

use Windwalker\Core\DateTime\Chronos;

$dt = new Chronos('now', 'Asia/Taipei');

// Simple create
$dt = Chronos::create();

// Quick get current time as format (Similar as date())
$time = Chronos::current('Y-m-d');

Auto set default timezone so you won't get PHP default timezone notice.

$dt = new Chronos('now', null);

Auto get global timezone, if you set timezone in Windwalker config, DateTime will auto load it.

$dt = new Chronos('now', true);

// OR

$dt = new Chronos('now', Chronos::TZ_LOCALE);

Convert a date string to another format

Chronos::toFormat($date, 'Y/m/d');

Convert Timezone

Chronos provides easy methods to convert timezone.

$date = '2015-03-31 12:00:00';

$date = Chronos::toServerTime($date, [format], [to tz]);

$date = Chronos::toLocalTime($date, [format], [to tz]);

// Or convert to other timezone

$date = Chronos::convert($date, [from], [to], [format]);
$date = Chronos::convert($date, 'Asia/Taipei', 'Asia/Tokyo', 'Y-m-d H:i:s');

Simple Properties

$datetime = new Chronos;


Pre-define Formats

$datetime = new Chronos;



Get Local Time

Add true to get local time, otherwise you will get UTC time.

$datetime = new Chronos('now', 'Asia/Taipei');

$datetime->format('Y/m/d H:i:s', true);
$datetime->toUnix(Chronos::TZ_LOCALE); // Same as true

Get Sql Format


// Use different DB instance

If you found a typo or error, please help us improve this document.