如何使用PHP获取特定日期的日期? [英] How can I get the day of a specific date with PHP

查看:119
本文介绍了如何使用PHP获取特定日期的日期?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想得到10月22日的这一天(星期日,星期一,...)。我如何做?

I want to get the day (Sunday, Monday,...) of October 22. How can I do that?

推荐答案

您可以使用 date 功能。

我正在使用 strtotime 来获取当天的时间戳;还有其他解决方案,例如 mktime

You can use the date function.
I'm using strtotime to get the timestamp to that day ; there are other solutions, like mktime, for instance.



例如, 'D'修饰符,用于三个字母的文本表示:


For instance, with the 'D' modifier, for the textual representation in three letters :

$timestamp = strtotime('2009-10-22');

$day = date('D', $timestamp);
var_dump($day);

您将获得:

string 'Thu' (length=3)

'修饰符,对于全文本表示:

And with the 'l' modifier, for the full textual representation :

$day = date('l', $timestamp);
var_dump($day);

你得到:

string 'Thursday' (length=8)

或'w' ,以获得一天的数量(0到6,0是星期日,6是星期六)

Or the 'w' modifier, to get to number of the day (0 to 6, 0 being sunday, and 6 being saturday) :

$day = date('w', $timestamp);
var_dump($day);

您将获得:

string '4' (length=1)



希望这有助于: - )


Hope this helps :-)

这篇关于如何使用PHP获取特定日期的日期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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