Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/275.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php:在date/strftime/strotime中更改语言_Php_Date_Strtotime_Strftime_Setlocale - Fatal编程技术网

Php:在date/strftime/strotime中更改语言

Php:在date/strftime/strotime中更改语言,php,date,strtotime,strftime,setlocale,Php,Date,Strtotime,Strftime,Setlocale,我试图让我的第二段代码的输出是荷兰语。 第一个代码给出了正确的输出,但是是英文的。我试着用荷兰语写,但通常我会在1970年1月1日、2015年12月12日或者什么都不写。 代码应该在本周的下周五给出,除非已经过了周一,否则下周五就是周五 我的工作代码是英文的 <?php $d = strtotime('today'); switch ($d) { case strtotime('monday'): case strtotime('friday'): case st

我试图让我的第二段代码的输出是荷兰语。 第一个代码给出了正确的输出,但是是英文的。我试着用荷兰语写,但通常我会在1970年1月1日、2015年12月12日或者什么都不写。 代码应该在本周的下周五给出,除非已经过了周一,否则下周五就是周五

我的工作代码是英文的

<?php
$d = strtotime('today');

switch ($d) {
    case strtotime('monday'):
    case strtotime('friday'):
    case strtotime('saturday'):
    case strtotime('sunday'):
        $ff = strtotime('next friday');
        $ffn = date('l d M', $ff);
        echo $ffn;
    break;
    case strtotime('tuesday'):
    case strtotime('wednesday'):
    case strtotime('thursday'):
        $ff = strtotime('next friday' . '+ 7days');
        $fft = date('l d M', $ff);
        echo $fft;
    break;
    default:
        echo "Something went wrong";
}
?>

我的代码给出了荷兰语输出,但日期错误(它给出的是今天的日期,而不是下周五/下周五)


顺便说一句,这是我在这里问的第一个问题,所以我可能有点含糊不清

我现在用str_替换。(对我来说)这是一种简单快捷的方式来获得我所需要的输出。但我现在只做了将近一年的编程,所以我修复它的方法可能不是最好的。但它现在起作用了(: 感谢所有回复帖子的人

这是我现在用str_替换得到的

<?php
$d = strtotime('today');
setlocale (LC_TIME,'NL_nl');
ini_set('intl.default_locale', 'nl_NL');
switch ($d) {
    case strtotime('monday'):
    case strtotime('friday'):
    case strtotime('saturday'):
    case strtotime('sunday'):
        $ff = strtotime('next friday');
        $ffn = date('l d F ', $ff);
        $dutch = str_replace (
            array('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December', 'Friday'),
            array('Jan', 'Feb', 'Mrt', 'Apr', 'Mei', 'Jun', 'Jul', 'Aug', 'Sep', 'Okt', 'Nov', 'Dec', 'Vrijdag'),
            $ffn);
        echo $dutch;
    break;
    case strtotime('tuesday'):
    case strtotime('wednesday'):
    case strtotime('thursday'):
        $ff = strtotime('next friday' . '+ 7days');
        $fft = date('l d F', $ff);
        $dutch = str_replace (
            array('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December', 'Friday'),
            array('Jan', 'Feb', 'Mrt', 'Apr', 'Mei', 'Jun', 'Jul', 'Aug', 'Sep', 'Okt', 'Nov', 'Dec', 'Vrijdag'),
            $fft);
        echo $dutch;
    break;
    default:
        echo "Something went wrong";
}
?>

只需使用strftime()和set_locale()函数输出日期。如果代码逻辑正确,则无需更改代码逻辑


是唯一支持本地化的PHP日期和时间函数

两者都使用,并且只使用英语

为了得到帮助,你需要先使用

不幸的是,的第二个参数没有标准化,它的值在某种程度上取决于运行PHP代码的操作系统

在类Unix系统(Linux、OSX)上,使用:

在Windows上,使用:

/* Set locale to Dutch */
setlocale(LC_TIME, 'nld_nld');

上面的代码片段是从
setlocale()
的文档中复制的。我更改了日期并测试了第一个示例(在Mac OSX上)但我手头没有Windows系统来检查第二个系统是否如广告中所宣传的那样工作。无论如何,我可以从过去的经验中看出,在Windows上需要使用的字符串与在类似Unix的系统上使用的字符串不同。如果需要在Windows上运行代码,可以在页面末尾找到有用的链接。

将荷兰日期转换为英语然后使用php的strotime函数获取下一个星期五,然后将其转换回荷兰语,也许php有一个本地化的日期;我不确定,但是您可以通过将days/months字符串from/to dutch to/from替换为days/months来轻松地创建一个日期english@NikosM.感谢您的回复,我将尝试一下(:您可以使用strftime()要以任何语言输出日期,为什么不在switch语句中返回正确的时间戳,然后将其与strftime()一起使用以荷兰语显示日期?@YasenZhelev我已经使用了它,但不知怎的,我把输出搞砸了(但语言确实改变了)。不过感谢您的回复(:谢谢你的回答,但是我用这个方法遇到的问题是我的代码没有给出正确的日期输出。但是我知道通常这种方法不会弄糟结果。str_replace对我有效,不会弄乱我的结果(到目前为止),所以我想我会继续使用str_replace。但至少我现在知道strftime()是如何工作的了。)etc工作(:thnxi正在尝试在我的laravel刀片视图中用法语显示日期这是我的代码”,但它仍然用英语显示
/* Set locale to Dutch */
setlocale(LC_TIME, 'nl_NL');

/* Output: woensdag  3 juni 2015 */
echo strftime("%A %e %B %Y", strtotime('2015-06-03'));
/* Set locale to Dutch */
setlocale(LC_TIME, 'nld_nld');