php 想打印当天的全名

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7063336/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 01:55:45  来源:igfitidea点击:

want to print full Name of the day

phpdate

提问by Nisha

I want to print name of the day giving numbers from 1 to 7.

我想打印日期从 1 到 7 的数字。

Ex:

前任:

<?php
 echo date("1");
?>

and want to get output as Monday. But it prints 1.

并希望获得输出为Monday. 但它打印1.

Can any one help me?

谁能帮我?

回答by

echo date ('l');

amazing what you find in the manual, its l not 1

您在手册中发现的内容令人惊讶,它不是 1

l (lowercase 'L') A full textual representation of the day of the week Sunday through Saturday

l(小写“L”)星期日到星期六星期几的全文表示

update

更新

sneakiness to not have to create your own array of day names

偷偷摸摸地不必创建自己的日期名称数组

$day='1'; 
echo date("l", mktime(0,0,0,8,$day,2011));// it will work for day 1-7 

回答by PHP Ferrari

Use like:

像这样使用:

$mydate = '2016-01-01';
echo date('l, F jS, Y', strtotime($mydate));
# Friday, January 1st, 2016

note the letter l(lower case of L)

注意字母lL 的小写)

回答by Mihai Iorga

you cannot do that with date()

你不能这样做 date()

date()= Returns a string formatted according to the given format string using the given integer timestamp or the current time if no timestamp is given.

date()= 返回根据给定格式字符串格式化的字符串,使用给定的整数时间戳或当前时间(如果没有给定时间戳)。

You can set an array with your values:

您可以使用您的值设置一个数组:

$dates = array("", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday");
echo $dates[1]; // will output Monday

if you want the current day name

如果你想要当前的日期名称

echo date ('l'); // (lowercase 'L')

In other words read the manual

换句话说,阅读手册

回答by Mehtab

$mydate = '2016-09-25';
date('l', strtotime($mydate));

It is "l" l for lock :P

锁定是“l” l :P

回答by Ahmed Mohamed

if some one using Carbon class which is inherited from the PHP DateTime class,

如果有人使用继承自 PHP DateTime 类的Carbon

Carbon::parse('yourdate')->formatLocalized('%A');

Carbon API localization

Carbon API 本地化

回答by smutty

function dt($val) { 
    $arrWeek = array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");
    return $arrWeek[$val];
}

回答by xaph

You can use

您可以使用

echo date('l');

Also if you want to localize it:

另外,如果您想对其进行本地化:

setlocale(LC_TIME, "C");//you need to change C with your locale.
echo strftime("%A");

will solve your problem.

将解决您的问题。