About Windwalker DateTime

Windwalker\Core\DateTime\DateTime 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 DataTime, see PHP DateTime


Windwalker DateTime supports Timezone as string.

use Windwalker\Core\DateTime\DateTime;

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

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

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

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

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

// OR

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

Convert Timezone

Windwalker DateTime supports easy methods to convert timezone.

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

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

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

// Or convert to other timezone

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

Simple Properties

$datetime = new DateTime;


Pre-define Formats

$datetime = new DateTime;



Get Local Time

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

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

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

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