CodeIgniter Forums
IntlDateFormatter gregorian calendar - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forum-28.html)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forum-30.html)
+--- Thread: IntlDateFormatter gregorian calendar (/thread-76858.html)



IntlDateFormatter gregorian calendar - mohs3n - 06-27-2020

Hi

IntlDateFormatter class lets us define a pattern for showing the dates. 
I use the following to show the date in the Georgian calendar :

Code:
$now = new DateTime();

$formatter = new IntlDateFormatter(
                "[email protected]=persian",
                IntlDateFormatter::FULL,
                    IntlDateFormatter::FULL,
                'Asia/Tehran',
                IntlDateFormatter::TRADITIONAL,
                "yyyy-MM-dd");

// It is now: 1396-12-14
echo 'It is now: ' . $formatter->format($now);

I've read the  CI4 documentation page https://codeigniter4.github.io/userguide/libraries/time.html , but I couldn't figure out how to do it in CI4.

Any help would be appreciated.


RE: IntlDateFormatter gregorian calendar - mohs3n - 06-28-2020

When I create a new instance of IntlDateFormatter in the controller I get this error:

Error
Class 'App\Controllers\Panel\Articles\IntlDateFormatter' not found

Is there anyway to use IntlDateFormatter class in CI4 ?


RE: IntlDateFormatter gregorian calendar - dave friend - 06-28-2020

(06-28-2020, 05:32 AM)mohs3n Wrote: When I create a new instance of IntlDateFormatter in the controller I get this error:

Error
Class 'App\Controllers\Panel\Articles\IntlDateFormatter' not found

Is there anyway to use IntlDateFormatter class in CI4 ?

I assume you wish to use PHP's IntlDateFormatter class?

Based on that error message it appears PHP is looking in the wrong namespace. Try adding a "use" clause to the file being executted.

PHP Code:
use IntlDateFormatter

This will let PHP know that the class is in the "root" PHP namespace.


RE: IntlDateFormatter gregorian calendar - mohs3n - 06-28-2020

(06-28-2020, 06:23 AM)dave friend Wrote:
(06-28-2020, 05:32 AM)mohs3n Wrote: When I create a new instance of IntlDateFormatter in the controller I get this error:

Error
Class 'App\Controllers\Panel\Articles\IntlDateFormatter' not found

Is there anyway to use IntlDateFormatter class in CI4 ?

I assume you wish to use PHP's IntlDateFormatter class?

Based on that error message it appears PHP is looking in the wrong namespace. Try adding a "use" clause to the file being executted.

PHP Code:
use IntlDateFormatter

This will let PHP know that the class is in the "root" PHP namespace.


Yes, that fixed the issue.
Thanks dave friend