strtotime With Different Languages?
From the docs
Parse about any English textual datetime description into a Unix
timestamp
Edit: Six years down the road now, and what was meant to be a side-note about why strtotime() was an inappropriate solution for the issue at hand became the accepted answer /p>
To better answer the actual question I want to echo Marc B's answer: despite the downvotes, date_create_from_format, paired with a custom Month interpreter will provide the most reliable solution
However it appears that there is still no silver-bullet for international date parsing built-in to PHP for the time being.
Php: Change language in date/strftime/strtotime
Just output the date using strftime() and set_locale() functions. No need to change your code logic if it is correct.
http://php.net/manual/en/function.strftime.php
http://php.net/manual/en/function.setlocale.php
<?php
$d = strtotime('today');
$format = '%A %d %b';
setlocale(LC_TIME, 'NL_nl');
setlocale(LC_ALL, 'nl_NL');
switch ($d) {
case strtotime('monday'):
case strtotime('friday'):
case strtotime('saturday'):
case strtotime('sunday'):
$ff = strtotime('next friday');
$ffn = strftime($format, $ff);
echo $ffn;
break;
case strtotime('tuesday'):
case strtotime('wednesday'):
case strtotime('thursday'):
$ff = strtotime('next friday' . '+ 7days');
$fft = strftime($format, $ff);
echo $fft;
break;
default:
echo "Something went wrong";
}
?>
Change language of the date stored in d-M-Y format php
Actually I use this in wordpress so I used date_i18n()
echo date_i18n('d-M-Y', strtotime( $date ));
How to solve a php strtotime language issue not sincronyzed with server bash language
From docs (emphasis mine):
strtotime
— Parse about any English textual datetime description into a Unix timestamp
In case you don't need the full power of strtotime()
(after all, you seem to be parsing logs from one single program) you can try IntlDateFormatter::parse()
. Here's a quick and dirty demo:
$fmt = new IntlDateFormatter('de_DE', null, null);
$fmt->setPattern('M-dd-yy hh:mm:ss');
$log_time = "Mai-05-20 17:22:36";
$unix_time = $fmt->parse($log_time);
echo date('r', $unix_time);
Tue, 05 May 2020 17:22:36 +0200
Note that a Unix time is a fixed moment in time, thus unaffected by time zones. I get +0200
when casting to local time because my PHP default time zone is currently CEST.
Convert Month Name into Number With Different Languages?
If you can integrate the external class dt try this:
$visit_date = "7 Dezembro, 2019";
dt::setDefaultLanguage('pt');
$dt = dt::create($visit_date);
echo $dt->format('Y-m-d');//2019-12-07
Internally, the class creates a translation table for every month when setting the language. The IntlDateFormatter class is used for this.
Note: The IntlDateFormatter class works independently of the server's local settings.
Is there any inbuild function to convert different language date into common date format in PHP
You can use str_replace
like below
$arrDates = array('12-ápr.-2018', '8-anp.2018', '11-Apr-2018');
foreach($arrDates as &$d){
$d = str_replace(['ápr.-','anp.','Apr-'],'4-',$d);
}
print_r($arrDates);
Live Demo
Output :
Array
(
[0] => 12-4-2018
[1] => 8-4-2018
[2] => 11-4-2018
)
Translating PHP weekdays and months
You are probably looking for the following:
http://php.net/manual/en/function.setlocale.php
http://php.net/manual/en/function.strftime.php
UPDATE
setlocale(LC_TIME, "fi");
echo utf8_encode(strftime('%A'));
RESULT
perjantaina
And this as a gift for you guys - the ISO language codes
Related Topics
Prevent Sent Emails Treated as Junk Mails Using PHP Mail Function
Adding Months to a Date in JavaScript
How to Strip a Tag and All of Its Inner HTML Using the Tag'S Id
PHP Get All the Images from Url Which Width and Height ≫=200 More Quicker
How to Use a String as an Array Index Path to Retrieve a Value
Cannot Modify Header Information - Headers Already Sent By... Wordpress Issue
Smtp Connect() Failed PHPmailer - PHP
Get the First N Elements of an Array
Return Index of Highest Value in an Array
Regular Expression Pattern to Match Url With or Without Http://Www
Elegant Way to Get the Count of Months Between Two Dates
How to Check If a String Starts With a Specified String
Preserve Key Order (Stable Sort) When Sorting With PHP'S Uasort
MySQLi_Fetch_Array While Loop Columns