[英]date(“F”, strtotime(day-month-year)) printing out the wrong value for the second month of the year
Just out of curiosity, anyone know why 出于好奇,有人知道为什么
echo date("F", strToTime("$day-02-$year"));
would print out March, originally I thought it was a common off by one error but 会打印出三月,本来我以为这是一个错误,但是
echo date("F", strToTime("$day-01-$year"));
prints out January and 打印一月和
echo date("F", strToTime("$day-03-$year"));
prints out march, so I am unsure of what is actually going on here??? 打印出三月,所以我不确定这里到底发生了什么???
any ideas 有任何想法吗
You run this script today, so $day=30;
您今天运行此脚本,因此
$day=30;
? ?
So, if you try to get the 30th day of February, it returns you the 2nd day of March - or March 1st in leap years. 因此,如果您尝试获取2月30日,则返回3月2日-leap年3月1日。 Obviously because February doesn't have enough days...
显然是因为二月没有足够的时间...
$day = 30;
$year = 2014;
echo date("r", strToTime("$day-02-$year"));
Output: 输出:
Sun, 02 Mar 2014 00:00:00 +0100
It's not a bug, it's a feature. 这不是一个错误,这是一个功能。
My problem was defaulting the day as a "j" i just made the default 01 if there was no day set and it works now, 我的问题是将日期默认设置为“ j”,如果没有设置日期,则我将默认设置设为01,现在可以使用了,
I have a calendar that I was going from month to month with simple buttons and the day was never set in my conditional statement I had that if the day was not set that the default was a lowercase j as soon as I changed that it responded with the correct name, So the answer to this question is to ensure that the default day is set to 1 if there is not going to be a day present such as when you are going from month to month 我有一个日历,每个月都要用简单的按钮进行操作,而条件语句中从未设置过日期,所以我有一个问题,即如果未设置日期,则默认值是小写的j,一旦更改,它就会响应正确的名称,因此此问题的答案是确保如果不存在某天(例如您一个月一个月到另一个月),则将默认日期设置为1
<?php
if (isSet($_GET['day'])) {
$day = $_GET['day'];
} else {
$day = date("01");
}
if (isSet($_GET['month'])) {
$month = $_GET['month'];
} else {
$month = date("n");
}
if (isSet($_GET['year'])){
$year = $_GET['year'];
} else {
$year = date("Y");
}
//calendar variable
$currentTimeStamp = strToTime("$day-$month-$year");
//get current month name
$monthName = date("F", $currentTimeStamp);
//get how many days are in the current month
$numDays = date("t", $currentTimeStamp);
//counter for calendar cells in loop
$counter = 0;
?>
like so! 像这样!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.