I need the names of the day (Monday, Tuesday, Wednesday, Thuesday, Friday, Saturday, Today).

我需要当天的名字(星期一,星期二,星期三,星期二,星期五,星期六,今天)。

I know this is a newby question and PHP has a date() function. But I tried and can't figure out how...

我知道这是一个新问题,PHP有一个date()函数。但我尝试了,无法弄清楚如何......

2 个解决方案

#1


0

According to the PHP Manual at http://php.net/manual/en/function.date.php, just use "l" as the format parameter to get the full name of the day.

根据http://php.net/manual/en/function.date.php上的PHP手册,只需使用“l”作为格式参数即可获取当天的全名。

So 23rd Mar 2014 is a Sunday, as echoed by

因此,2014年3月23日是一个星期天

<?php
echo date ("l", mktime(0, 0, 0, 3, 23, 2014));
// Echoes Sunday
?>

To get past 7, 6, 5 or 10000 days (or number of days in the future) from the current day, according the information at this page, just use negative or positive integers in a string in the strtotime function:

要从当天开始过去7天,6天,5天或10000天(或将来的天数),根据此页面上的信息,只需在strtotime函数中的字符串中使用负整数或正整数:

<?php
$backcount = -4;
echo date ("l", strtotime("$backcount day"));
// Executed on 23 Mar 2014 will give Wednesday
?>

Knowing this, you can apply a for loop to get what you need. And if want "Today" instead of the full name of the current day, just add an if condition to handle the situation where the backcount variable is zero.

知道这一点,你可以应用for循环来获得你需要的东西。如果想要“今天”而不是当天的全名,只需添加一个if条件来处理backcount变量为零的情况。

更多相关文章

  1. 获取上周五的日期,除非今天是星期五使用T-SQL
  2. 黑马程序员 Java中根据YYYY-MM-DD格式的日期计算为星期几的两种

随机推荐

  1. 疯狂XML学习笔记(6)-----------XML拓展
  2. 疯狂XML学习笔记(5)-----------XML DOM
  3. 疯狂XML学习笔记(4)------------XML的对手
  4. android如何使用DOM来解析XML+如果做一个
  5. XML简明教程(3)
  6. 疯狂XML学习笔记(3)-----------XML与DTD
  7. android如何使用DOM和SAXParserFactory来
  8. XML简明教程(2)
  9. android使用XmlPullParser来解析XML文件
  10. XML简明教程(1)