[英]Covert html date value to RFC 2822
I have following code, 我有以下代码,
$date = $_POST["s-date"]; // get from form. value pass correctly.
$time = "".$hour.":".$minute.":".$second.""; // ok
echo RFC2822($date,$time);
function RFC2822($date,$time = '00:00') {
$array = list($d, $m, $y) = explode('-', $date);
list($h, $i, $s) = explode(':', $time);
return date('r', mktime($h,$i,0,$m,$d,$y));
}
When I execute this script, time fragment is printed correctly, But date is displayed as Jul 08 2025 always even passing different date to the function. 当我执行此脚本时,将正确打印时间片段,但日期始终显示为2025年7月8日,甚至将不同的日期传递给函数。 How to fix this.
如何解决这个问题。
You must need to check the value of this input $_POST["s-date"]
it must be follow this format of date: 您必须检查此输入
$_POST["s-date"]
它必须遵循以下日期格式:
`DD-MM-YY`
because, you are creating list in this format (DD-MM-YY): 因为,您正在以以下格式(DD-MM-YY)创建列表:
$array = list($d, $m, $y) = explode('-', $date);
UPDATE 1: 更新1:
As you mentioned, you are using HTML date and HTML date format is 'YYYY-MM-DD'
, now just change the list variable order as per date format. 如前所述,您使用的是HTML日期,而HTML日期格式为
'YYYY-MM-DD'
,现在只需更改日期格式的列表变量顺序即可。
From what I can gather your problem lies not with the code you've shared, but somewhere else. 据我所知,您的问题不在于您共享的代码,而在于其他地方。 If I copy-paste your script and put in a fixed date on $date, it works as expected.
如果我复制粘贴您的脚本并在$ date上放置一个固定的日期,它将按预期工作。 (I've removed $time for missing vars)
(我已删除缺少变量的$ time)
$date = "27-02-2014";
echo RFC2822($date);
function RFC2822($date,$time = '00:00:00') {
$array = list($d, $m, $y) = explode('-', $date);
list($h, $i, $s) = explode(':', $time);
return date('r', mktime($h,$i,0,$m,$d,$y));
}
Outputs 产出
Thu, 27 Feb 2014 12:00:00 +0100
From this I expect that your $_POST['s-date']
var somehow gets a fixed 08-07-2025 or some other input that will make it 08 Jul 2025. 由此,我希望您的
$_POST['s-date']
var以某种方式获得固定的08-07-2025或其他一些输入,使其变为2025年7月8日。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.