PHP中本月的第三个星期四 [英] Third Thursday of the month in php

查看:47
本文介绍了PHP中本月的第三个星期四的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种方法可以在php中找到具有特定日期的星期几.

Is there a way to find the day of the week in php with a particular date.

我不是故意的

date('D', $timestamp);

我的意思是,如果我要提供类似2010-10-21的日期,它将返回第三周四".

I mean if I was to supply a date like 2010-10-21 it would return "third thursday".

推荐答案

不是直接的,您需要一个帮助函数:

Not directly, you need a helper function for that:

function literalDate($timestamp) {
    $timestamp = is_numeric($timestamp) ? $timestamp : strtotime($timestamp);
    $weekday   = date('l', $timestamp);
    $month     = date('M', $timestamp);   
    $ord       = 0;

    while(date('M', ($timestamp = strtotime('-1 week', $timestamp))) == $month) {
        $ord++;
    }

    $lit = array('first', 'second', 'third', 'fourth', 'fifth');
    return strtolower($lit[$ord].' '.$weekday);
}

echo literalDate('2010-10-21'); // outputs "third thursday"

工作示例:

http://codepad.org/PTWUocx9

这篇关于PHP中本月的第三个星期四的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆