dongquming3255 2014-11-17 12:11
浏览 31
已采纳

更改php日期输出语言

I am using few variables to store different php dates in desired formats like following:

$today = date('Y-m-d');
$todayPretty = date('d. M');
$oneMonthBefore = date('Y-m-d', strtotime('-1 months'));
$oneMonthBeforePretty = date('d. M', strtotime('-1 months'));
$oneMonthBefore2 = date('Y-m-d', strtotime($this->oneMonthBefore .' -1 day'));
$oneMonthBefore2Pretty = date('d. M', strtotime($this->oneMonthBefore .' -1 day'));
$twoMonthsBefore = date('Y-m-d', strtotime('-2 months'));
$twoMonthsBeforePretty = date('d. M', strtotime('-2 months'));
$currentMonth = date('F');
$previousMonth = date('F', strtotime('-1 months'));

Unfortunately I need them in a different language like danish for example so I've set up the following with no results:

setlocale(LC_ALL, "da_DK.UTF-8");

I've read that I have to use strftime function but how I should approach this when it comes to the variables that doesn't use strtotime in my case? Any help or guidance is more than welcomed.

  • 写回答

2条回答 默认 最新

  • dousao8152 2014-11-17 12:30
    关注

    At first you should check if you have installed your locale with:

    locale -a 
    

    in commandline.

    if not you can do that on ubuntu/debian with:

    sudo locale-gen da_DK.UTF-8
    

    In PHP you can also trying multiple deff's if your code will develop on windows and deploy on linux, like this:

    <?php
    setlocale (LC_ALL, 'de_DE.UTF-8', 'de_DE@euro', 'de_DE', 'de', 'ge', 'de_DE.ISO_8859-1', 'German_Germany');
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥100 需要跳转番茄畅听app的adb命令
  • ¥50 寻找一位有逆向游戏盾sdk 应用程序经验的技术
  • ¥15 请问有用MZmine处理 “Waters SYNAPT G2-Si QTOF质谱仪在MSE模式下采集的非靶向数据” 的分析教程吗
  • ¥50 opencv4nodejs 如何安装
  • ¥15 adb push异常 adb: error: 1409-byte write failed: Invalid argument
  • ¥15 nginx反向代理获取ip,java获取真实ip
  • ¥15 eda:门禁系统设计
  • ¥50 如何使用js去调用vscode-js-debugger的方法去调试网页
  • ¥15 376.1电表主站通信协议下发指令全被否认问题
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证