View previous topic :: View next topic |
Author |
Message |
vkrox Smarty Rookie
Joined: 12 Jul 2018 Posts: 5
|
Posted: Tue Jul 24, 2018 7:30 am Post subject: Get timezone in Smarty |
|
|
Hi,
I want to get Europe London time with smarty. Please help me |
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Wed Jul 25, 2018 3:38 pm Post subject: |
|
|
Define "get"? Display current time in a given timezone? Convert specific time to a given timezone?
In both cases, you'd need a custom modifier for that.
Something along the lines of
Code: | $nf = new \NumberFormatter("ru_RU", \NumberFormatter::CURRENCY);
$cs = ini_get('output_encoding') ?: ini_get('iconv.output_encoding') ?: ini_get('default_charset') ?: 'ISO-8859-1';
$tpl->registerPlugin('modifier', 'price',
function($price, $currency = 'RUB')
use($nf, $cs)
{
return iconv('UTF-8', "$cs//IGNORE", $nf->formatCurrency($price, $currency));
}
);
unset($nf, $cs);
| but using DateTime/DateTimeFormatter/DateTimezone. |
|
Back to top |
|
vkrox Smarty Rookie
Joined: 12 Jul 2018 Posts: 5
|
Posted: Wed Jul 25, 2018 4:12 pm Post subject: |
|
|
I want to get the current UK time with smarty |
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Fri Jul 27, 2018 1:48 am Post subject: |
|
|
vkrox wrote: | I want to get the current UK time with smarty |
AnrDaemon wrote: | Define "get"? |
|
|
Back to top |
|
vkrox Smarty Rookie
Joined: 12 Jul 2018 Posts: 5
|
Posted: Fri Jul 27, 2018 1:50 am Post subject: |
|
|
means, display UK time and need that uk time in a variable |
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Fri Jul 27, 2018 1:58 am Post subject: |
|
|
Assign all values to Smarty in your own code.
And use custom formatter to display it. |
|
Back to top |
|
vkrox Smarty Rookie
Joined: 12 Jul 2018 Posts: 5
|
Posted: Fri Jul 27, 2018 1:59 am Post subject: |
|
|
but the code you have given is for currency right? i need to get the current time of UK |
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Fri Jul 27, 2018 3:57 am Post subject: |
|
|
Do you seriously expect me to do your job for you? For free, none the less?
I gave you the principle, it's not a rocket science to modify a working code for your own case.
Especially not since all intl classes follow the same suit. |
|
Back to top |
|
|