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

使用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条回答 默认 最新

相关推荐 更多相似问题