Language based php output time

I am working on a project that requires me to list 24 hours in the locale format.

Here is what I have:

$time_fmt = datefmt_create(ICL_LANGUAGE_CODE, IntlDateFormatter::LONG, IntlDateFormatter::LONG, '', IntlDateFormatter::GREGORIAN, 'H:i'); echo datefmt_format($time_fmt, mktime(1, 0)); 

This seems to happen 01:00 or 1:00 depending on the locale. But he displays "8:".

How can I use datefmt_create () and dtefmt_format () to display 24 hours in local format?

+4
source share
2 answers

This works: (verified)

 date_default_timezone_set('America/Los_Angeles'); setlocale(LC_TIME, "en_US"); $times = array( '00:00:00', '01:00:00', '02:00:00', '03:00:00', '04:00:00', '05:00:00', '06:00:00', '07:00:00', '08:00:00', '09:00:00', '10:00:00', '11:00:00', '12:00:00', '13:00:00', '14:00:00', '15:00:00', '16:00:00', '17:00:00', '18:00:00', '19:00:00', '20:00:00', '21:00:00', '22:00:00', '23:00:00' ); foreach( $times as $time ){ echo strftime("%X", strtotime($time)) . "\n"; } 
0
source

Something like this should work

 $time = strtotime('English Date With Time'); date_default_timezone_set('America/Los_Angeles or wherever'); echo date('H:i', $time); 

If you just make a clock, not a date, then just know what time zone you are in. Translate everything into UTC and do the math modulo 24.

0
source

Source: https://habr.com/ru/post/1500851/


All Articles