开发者

want to print full Name of the day

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

Ex:

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

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

Can a开发者_开发百科ny one help me?


echo date ('l');

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

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

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 


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)


you cannot do that with 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.

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


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

It is "l" l for lock :P


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


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

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

Carbon API localization


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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜