开发者

php date ('m') is show single digit month and not double

开发者 https://www.devze.com 2023-01-30 11:50 出处:网络
according to php.net date(\'m\') should should 01 but i\'m getting 1 instead dirloc = date(\'Y\') . \"/开发者_JAVA技巧\" . date(\'m\') . \"/\" . $word_id . \"/\";

according to php.net date('m') should should 01 but i'm getting 1 instead

dirloc = date('Y') . "/开发者_JAVA技巧" . date('m') . "/" . $word_id . "/";


Install PHPUnit. Run the following UnitTest:

// make sure PHPUnit is included

class DateTest extends PHPUnit_Framework_TestCase
{
    public function setup()
    {
        date_default_timezone_set('UTC');
    }
    public function getDates()
    {
        return array(
            array('01', 'Jan'),
            array('02', 'Feb'),
            array('03', 'Mar'),
            array('04', 'Apr'),
            array('05', 'May'),
            array('06', 'Jun'),
            array('07', 'Jul'),
            array('08', 'Aug'),
            array('09', 'Sep')
        );
    }
    /**
     * @dataProvider getDates
     */
    public function testDateReturnsMonthWithLeadingZero($expected, $month)
    {
        $this->assertSame($expected, date('m', strtotime($month)));
    }
}

If the test fails with any of the given test dates, collect your PHP version and Operating system and file a bug with the PHP bugtracker. If the test passes with all the test dates, you are doing something else wrong.

0

精彩评论

暂无评论...
验证码 换一张
取 消