dongzou1964 2018-07-13 07:56
浏览 117
已采纳

使用Intl(PHP)将西班牙语日期转换为时间戳

I need to convert date written in the natural language to timestamp or any other standard date format. Dates are in four languages: English, German, French, and Spanish. I can convert all except Spanish date with Intl extension.

Example of date in natural languages:

// es - 19 de julio de 2017
// fr - 2 février 2018
// en - May 16, 2016
// de - 27 Juni 2018

French date parse works fine

$df = \IntlDateFormatter::create(
    'fr_FR',
    \IntlDateFormatter::MEDIUM,
    \IntlDateFormatter::NONE,
    'Europe/Kiev'
);

$timestamp = $df->parse('2 fevrier 2018'); // 1517518800

But Spanish, return false

$df = \IntlDateFormatter::create(
    'es_ES',
    \IntlDateFormatter::MEDIUM,
    \IntlDateFormatter::NONE,
    'Europe/Kiev'
);

$timestamp = $df->parse('19 de julio de 2017'); // false

What do I do wrong?

  • 写回答

1条回答 默认 最新

  • duanjieyi6582 2018-07-13 08:03
    关注

    You shouldn't have used de in your date.

    $timestamp = $df->parse('19 julio 2017'); // false
    echo $timestamp;
    

    output is

    1500411600

    will work perfectly.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置