Snippet · Mecha CMS

Code snippet collection for developers.

Automatic Date Format

Author: Taufik Nurrohman · 416 Views

Tweet

Automatically set date format based on user language.

Table of Content

Date formats contained in the Date class only support for en-us and id-id format:

  • en-usWednesday, September 26, 2018
  • id-idWednesday, 26 September 2018

By replacing the - character with _, you can call the date format based on the current site language:

<?php echo $page->date->{str_replace('-', '_', $site->language)}; ?>

Missing Date Format 

Add your own localized date format this way:

Date::set('ja_jp', function($o, $language) {
    return $o['year'] . '/' . $o['month'] . '/' . $o['day'];
});

0 Comments

No comments yet.