dsb0003795 2016-12-16 12:52
浏览 30
已采纳

PHP解析德语日期[重复]

This question already has an answer here:

I have a question about my code below. How can I format a German Date, for example "Di, 02.Okt 2012" to "2012-10-02"?

I already checked many sites for a solution but did not found something which could help me.

    $value ='Di, 02.Okt 2012';
    $tempdate = $value;
    $tempdate = substr($tempdate,-11);
    $tempdate = date('Y-m-d',$tempdate);

Output: 1970-01-01

Solved:

$value = 'comes from a foreach loop'; 

$tempdate = $value;
    $tempdate = substr($tempdate,-11);
    $tempdate = str_replace('.Jan ', '-01-', $tempdate);
    $tempdate = str_replace('.Feb ', '-02-', $tempdate);
    $tempdate = str_replace('.Mär ', '-03-', $tempdate);
    $tempdate = str_replace('.Apr ', '-04-', $tempdate);
    $tempdate = str_replace('.Mai ', '-05-', $tempdate);
    $tempdate = str_replace('.Jun ', '-06-', $tempdate);
    $tempdate = str_replace('.Jul ', '-07-', $tempdate);
    $tempdate = str_replace('.Aug ', '-08-', $tempdate);
    $tempdate = str_replace('.Sep ', '-09-', $tempdate);
    $tempdate = str_replace('.Okt ', '-10-', $tempdate);
    $tempdate = str_replace('.Nov ', '-11-', $tempdate);
    $tempdate = str_replace('.Dez ', '-12-', $tempdate);
    $tempdate = date('Y-m-d',strtotime($tempdate));

    echo $tempdate.'<br/>';

This is the solution for many Dates. ^^ i hope i can help with it

</div>
  • 写回答

3条回答 默认 最新

  • dongqiao9015 2016-12-16 13:09
    关注

    This should work for your example.
    When u have another date, replace "Okt" with another month and "-10-" with the number of the month.

    $tempdate = 'Di, 02.Okt 2012';
    $tempdate = str_replace('Di,', '', $tempdate);
    $tempdate = str_replace('.Okt ', '-10-', $tempdate);
    $tempdate = date('Y-m-d', strtotime($tempdate));
    echo $tempdate;
    
    // output: "2012-10-02"
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记