【问题标题】:How to format months in german and minus one month如何用德语格式化月份和减去一个月
【发布时间】:2019-12-05 12:48:25
【问题描述】:

我的问题是我只希望当前月份以 德语 格式进行格式化,不幸的是,到目前为止,这不适用于我的进度。但另外,月份应该以 German 显示,并且总是 -1(所以现在是 11 月而不是 12 月)。最简单的方法是什么?为什么我不能通过setlocale 来做?

提前谢谢你:)

这是我的代码:

<?php
setlocale (LC_ALL, 'de_DE@euro', 'de_DE', 'de', 'ge');
echo $newdate = date("m.Y", strtotime("-1 months"));
?>

【问题讨论】:

  • php.net/manual/en/function.date.php: “要格式化其他语言的日期,您应该使用 setlocale() 和 strftime() 函数而不是 date()。”
  • DateTime with the DateTimeZone set ... 我发现setlocale 不可靠 - 特别是在 Windows 开发环境中。

标签: php date strtotime setlocale


【解决方案1】:

好的,已经从 php.net 找到了解决方案..

<?php
//showing Dates in German lanuage:
function formatDateString($stamp) {
    //initalise String:
  //Gettting the months set up...
                $monate = array(1=>"Januar",
                2=>"Februar",
                3=>"M&auml;rz",
                4=>"April",
                5=>"Mai",
                6=>"Juni",
                7=>"Juli",
                8=>"August",
                9=>"September",
                10=>"Oktober",
                11=>"November",
                12=>"Dezember");

  //Getting our Month
                $monat = date("n", strtotime("-1 months"));

    //Getting the Days set up....
                $tage = array("Sonntag","Montag","Dienstag","Mittwoch",
                    "Donnerstag","Freitag","Samstag");

$printme = $monate[$monat];

return $printme;
}

并添加 strtotime("-1 months") 以提前一个月

但感谢您的快速帮助:)

【讨论】:

    猜你喜欢
    • 2020-03-26
    • 1970-01-01
    • 2011-06-04
    • 1970-01-01
    • 2014-05-10
    • 1970-01-01
    • 2017-05-16
    • 1970-01-01
    相关资源
    最近更新 更多