I'm using CodeIgniter and I have tons of date('format',strtotime(unixtimestamp)) methods in my views.
So when user choose his own language and I would like to automatically convert all datetimes to locale time zone for all my views.
Is there any recursive way to make this possible?
The infos i get from users is their selected language:
it = Italian
fr = French
es = Espanol
etc... so i get lang key codes
I sincerely can't get anything out of my head.
Any help appreciated, really. Thanks.
Depending how you store the timezone preference, you could use date_default_timezone_set().
For example:
date_default_timezone_set('America/New_York');
Note: I'm not familiar with CodeIgnitor, but so long as you set this in a bootstrap or config script, that is before you call date(), this will automatically display all dates in the set locale.
Related
I'd like to display the Hebrew month automatically in my Mailchimp's newsletter. So I think I need to set the date locale to Herbew. How do I set the date locale?
I saw this similar question from 2013 but it doesn't work anymore. (maybe the functionality has changed?)
I'm using this list (cheat sheet) of Mailchimp tags.
Based on tag *|DATE: F Y|* and *|TRANSLATE:HE|* it should give me the desired result, but instead supplies me a list of languages to translate my page into and I just want the date locale to be set to Israel.
Information about PHP format and date locale: here.
Thanks in advance!.
Unfortunately, I don't think that's possible. Would love if I was wrong though.
I'm working on a bilingual WordPress project which is translated with TranslatePress plugin. Sadly TranslatePress ignores all number fields and won't let me change their values depending on the countries number format. The offiical support team told me, it's not possible at this moment.
The original language of the page is German and the second language is English. The page contains a lot of number information for cities etc. which are put in like this 13.502.552 Since TranslatePress won't let me convert these numbers by hand I'm looking for a way to convert them for the entire site maybe through functions.php, is this possible? Is there a way to check if locale is set to en_GB and to convert all the numbers to 13,502,552 on the fly?
I already came across number_format_i18n, but could not find a way to use it properly for my purpose.
Any ideas?
I'm just wondering how the php function date() works? Like how does it determine time and date to return?
For example if my php code on a page looked something like this:
<?php
echo date("h:i:sa");
?>
It will simply echo out (for example) 11:18:24am, but let's say a site visitor from another country visits page, will the time returned be appropriate for their timezone? Hopefully this question makes sense, i only ask because I couldn't find anything on Google when searching how php date() function works.
The date method is documented here: https://secure.php.net/manual/function.date.php
As php scripts are executed on server side, it uses the current date/time of the server, formats and returns it. - There is no conversions for the timezone of visitors of your website. If you need localized times, you need to change the timezone manually.
I had the same problem but here is how i solved it. In the php.ini the timezone is static and set according to the server but you can override this by using date_default_time_zone function. for example you can create a script that tests a visitor location then loads parameters to date_default_timezone_set("continent/city"); according to your visitor location. i hope this works
I just noticed something really nice on the Google Analytics signup page for adding a new domain. First you pick a country them you pick your timezone. Instead of showing a huge Timezone list though they populate the timezone list with only timezones that are available for the country you have selected. I think this is a great idea to make picking a timezone easiar for some users.
So I would like to do this with jQuery since most my other javascript is using jquery already. Has anyone seen any existing jquery script that can do this for me? Or possibly how I can figure out what timezones are in each country?
Can't help with jQuery but for how to figure out what timezones are in each country, you can use DateTimeZone::listIdentifiers() with DateTimeZone::PER_COUNTRY as first argument and the ISO 3166-1 compatible country code as second argument, e.g.
DateTimeZone::listIdentifiers(DateTimeZone::PER_COUNTRY, 'GB');
Note: PHP 5.3 is required.
You can construct the data you want from this table: http://www.datelib.de/Timezones.shtml.en. You would simply group by the Country code column. Probably the best way to go would be to throw all this data into a database table and use some AJAX magic to handle select menu onchange events.
my site changes its locale dependent upon either user settings or browser settings (where the user hasn't set their preference). I am using amline charts, the stock chart specifically, which requires the date format in 'MM/DD/YYYY' or 'DD-MM-YYYY', I guess so the chart knows how to understand the dates. There are many ways to format a date dependent upon the computer locale, however I can't find a way to get the locale format (as above).
What's the problem?
date('m/d/Y')
or
date('d-m-Y')