php 日期选择器 Web 浏览器

标签 php html date datepicker

我正在开发一个简单的日期选择器,它默认显示今天的日期。问题是我不能让它在不同的浏览器上像 Chrome、firefox 和 Opera 一样工作。

<?php
  $timezone = "Europe/Oslo";
  date_default_timezone_set($timezone);
  $today = date("d.m.Y");
echo $today." <br>";
?>

<html>
  <body>
    <input type="date" value="<?php echo $today ?>">
  </body>
</html>

谷歌浏览器:

enter image description here

火狐:

enter image description here

歌剧:

enter image description here

正如您在 firefox 中看到的那样,我得到了日期,但在 GC 或 Opera 中却没有。

但是当我将日期格式化为:$today = date("Y-m-d");

在谷歌浏览器中看起来像这样:

enter image description here

歌剧:

enter image description here

火狐:

enter image description here

最佳答案

input type="date"在 firefox 中不受支持,所以它只接受文本的值 在 chrome 中默认格式是 dd/mm/yyyy

opera 默认格式是 mm/dd/yyyy

如果你只想显示日期,将类型更改为文本将支持任何格式

<input type="text" value="<?php echo $today ?>">

关于php 日期选择器 Web 浏览器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22245334/

相关文章:

sql - 从SQLite中的特定日期检索数据

php - 如何将图像存储到文件系统(在 Internet 上)并将路径存储到数据库?

javascript - 从 Excel 导出 XML 并保持日期格式

php - 如何使用 Python 和 Flask 查找 HTML 单选按钮的值?

javascript - 如何为注册表创建圆形轮廓仪

html - 字体系列不变

javascript - AureliaJS - 从 div 或 JavaScript 导航到路由?

python - 为什么 pandas 在日期索引表中查找日期时会生成 KeyError?

javascript - 从 Controller 输出到 HTML 表单

php - 斜线附加到我的所有帖子中