2011-10-31 12:47

PHP date()函数在时钟更改后返回错误的值

  • date
  • mktime
  • function
  • php

I have a simple function to convert a month from its number to name, i.e 10 to October

function convertToName($month) {  
    $month = date('F', mktime(0, 0, 0, $month));

    return $month;

This was working fine, up until, it seems, the clocks went back an hour. I'm now getting the wrong name back.

I've tried defining the timezone with date_default_timezone_set, but still nothing.

What's weird is, if you pass the function 10, it returns October, but pass it 11 or 12, it returns December, pass 1, January, 2 and 3 returns March, and so on.

I'm guessing there must be a pretty simple fix, but can't seem to find an answer anywhere,

any help would be appreciated,


  • 点赞
  • 回答
  • 收藏
  • 复制链接分享