Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert PHP variable date to local date in Hebrew

I convert a string in PHP to a date variable and need to print it in the local date in Hebrew language. I print the date to the page with date('M'); which results in March, in English, and my desired result is to print it in the local Hebrew language which should result in מרץ.

I know that there is way to create array and translate each name of month and day manually but I'm interested to convert the date variable that I have into $date into the local PHP date in Hebrew language. What will be the best way to do it?

like image 879
Yossi Aharon Avatar asked May 24 '26 13:05

Yossi Aharon


1 Answers

You need to set the locale first:

if (setlocale(LC_ALL, 'he_IL') === false) {
    throw new Exception("Locale not available on this machine.");
}

And then use strftime(), as date() doesn't respect locale settings:

echo strftime('%B');

Also note that your system needs to have the correct locale installed, which you can list via the command line with locale -a.

like image 151
Alex Howansky Avatar answered May 27 '26 03:05

Alex Howansky



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!