【问题标题】:How to enable type=“date” in every browsers (include phones)如何在每个浏览器(包括手机)中启用 type=“date”
【发布时间】:2015-04-25 07:16:39
【问题描述】:

日期有一个大问题,<input type="date"> 在 Mozilla Firefox 中不起作用,但在 IOS、Windows Phone 和其他浏览器中起作用。

是否可以在 Mozilla Firefox 中修复此问题并将日期格式设置为 dd-mm-yyyy

【问题讨论】:

标签: javascript html


【解决方案1】:

我在 FireFox 中使用日期输入。不要紧。提交表单后,我仍然在提交日期使用strtotime()

$date = strtotime ($_POST['date']);

我有一个 PHP 脚本可以计算两个日期之间的天数。

两个日期之间的天数

这张图片来自 FireFox:

<?php
$to = strtotime($_GET['to']);
$from = strtotime($_GET['from']);
if (!$from && !$to){
  $from = '8/21/2001';
  $to = '5/27/2014';
  $answer = "<h2>Number of days between<br/>Tuesday the 21st of August 2001 and<br/>Tuesday the 27th of May 2014 is<br/>4,662 days</h2>";
}
else {
  $days = number_format(intval(($to - $from) / 86400));
  $d1 = date('l \t\h\e jS \of F Y ',$from);
  $d2 = date('l \t\h\e jS \of F Y ',$to);
  $answer = "<h2>Number of days between<br/>$d1 and<br/>$d2 is<br/>$days days</h2>";
  $to = $_GET['to'];
  $from = $_GET['from'];
}
echo <<<EOT
<form method="get" action-"dates2days.php">
From: <input type="date" name="from" value="$from"/><br/>
To:&emsp;&ensp;<input type="date" name="to" value="$to" /><br/>
<input type="submit" value="&emsp;Get Days Between Dates&emsp;"/>
$answer
</form>
EOT;
?>

【讨论】:

  • 添加了 FireFox 示例。
猜你喜欢
  • 2014-05-04
  • 2012-04-28
  • 2014-01-09
  • 2013-11-21
  • 2023-03-16
  • 2011-12-08
  • 2022-01-18
  • 1970-01-01
  • 2017-01-16
相关资源
最近更新 更多