【问题标题】:using strftime for 31 december shows next year在明年 12 月 31 日的节目中使用 strftime
【发布时间】:2013-12-11 16:39:16
【问题描述】:

使用此代码,

   setlocale(LC_ALL, 'fr_FR');
    $end_date_formatted = utf8_encode(strftime("%d %B %G", mktime(0, 0, 0, $month_end, $day_end, $year_end)));

strftime 仅返回 12 月 31 日的正确年份。 它应该显示 2013 年 12 月 31 日,但显示的是 2014 年 12 月 31 日

【问题讨论】:

  • $day_end, $month_end, $year_end 传递了哪些值?

标签: php timestamp locale strftime


【解决方案1】:

are 使用了 mktime() 错误。它是:

int mktime ([ int $hour = date("H") [, int $minute = date("i") [, int $second = date("s") [, int $month = date("n") [, int $day = date("j") [, int $year = date("Y") [, int $is_dst = -1 ]]]]]]])

...你有:

mktime(0, 0, 0, $day_end, $month_end, $year_end)

解决了这个问题,您可能遇到了note in the strftime() manual page 警告的问题:

注意:基于 ISO 8601:1988 周数的 %G 和 %V 如果编号系统为 没有完全理解。请参阅本手册页中的 %V 示例。

2013 年 12 月 31 日属于明年的第一个 ISO 周。

你可能想要%Y

【讨论】:

  • 这可以解释,添加任何超过 12 的东西都会自动将年份推高
  • 我的错,它的 mktime(0, 0, 0, $month_end, $day_end, $year_end)。编辑问题
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-01-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-01-17
相关资源
最近更新 更多