Locale date format in PHP5 - php

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')

Related

Mailchimp - How to set date locale in a campaign?

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.

Issue in time-stamp date in php

I am having trouble in the timestamp.
When I am using the LAMP in Ubuntu, then it works with correct date which I entered, but on other systems it show 1 day back's date.
I don't know what I need to do now. I have stored the timestamp in my database. But when I am showing it on my web application, it works fine in the LAMP but not in others.
When I am converting the timezone to online converter it shows backdated result. What do I do now?
You can set PHP default timezone before reading the date from the timestamp.
Add the following line before reading the date.
date_default_timezone_set('Asia/Calcutta');
Let me know if this helps.
References:
http://php.net/manual/en/function.date-default-timezone-set.php
http://php.net/manual/en/timezones.php
The timestamp stored is correct, Please set the default time zone in your PHP application to let the system know which timezone you are using then it will store the correct time zone. the below link would help you.
I am assuming you are storing timestamp in DB and retrieving it to display
http://php.net/manual/en/function.date-default-timezone-set.php
Thanks

Force localization for os.date()

I'm building a server reporting system in Lua and C++, using the SMFL library and I've got a bit stuck on a potential issue.
The target of this script is that it creates a HTML file (with PHP within it) and uploads it to my webserver, for reporting purposes.
The name of the upload file will be '[process id][client IP][date].php', so we'll get something like '1234_199.123.45.7_31/01/2014.php', and clearly the date format needs to be in the European format.
I use the os.date("%x"), but it reports the date in the local machine's regional type, but it needs to be the dd/mm/yyyy format, regardless of the region settings of the client.
I've looked on how to do this, but I've only been able to get the time offset and not force os.date("%x") to use a specific region.
How can I forceos.date("%x") to use the dd/mm/yyyy format?
Lua's os.date accepts a format specifier, which is same as strftime. Based on strftime's docs, the format you want is obtained via
os.date("%d/%m/%Y")
You could use:
os.date("*t")
This returns a table with the date-time components, like:
With this data you can build a custom formatting function, based in T.day, T.month and T.year

PHP - Codeigniter set views datetime to locale

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.

PHP Date formatting DST

I generate a unix-timestamp in the adminpanel of my site with a modified version of the jquery datetime-picker.
This timestamp get's saved into a mySQL database and in the frontend I output it via the strftime() function.
As the site has multiple admins and everybody began to add content, I encountered an offset of 1h in the output time, due to the timezone we're in (GMT+1). Because content was already added, I couldn't edit the function which generates the date and writes it to the db, so I had to edit the output function in the frontend.
I thought it would be clever to just add (myTime+3600) as an argument of the strftime function. Everything worked fine and more content got added.
Now the problem is, that all content assigned a date in april 2013 is an hour to late because of the Daylight saving time.
I only have the timestamp to work with so I somehow need to get whether a date needs the 1h offset or not. Any ideas on how to do that without adding a timezone at the timestamp generating function?
There is a function.
Any recommendations are welcome!
Example:
frontend-code:
strftime("%d. %B %Y / %H:%M Uhr",new_timestamp+3600);
For 13.March 2013 16:30 I get the correct output.
For 13. April 2013 16:30 I get 17:30
set the application default timezone using this http://php.net/manual/en/function.date-default-timezone-set.php that way regardless of what timezone the client is in it should force the timestamps into your primary timezone.
You may also need to edit the datetimepicker inits to force jquery to use the server based timezone too.

Categories