PHP时间戳到HTML 5输入类型=日期时间元素

2024-04-12php开发问题
14

本文介绍了PHP时间戳到HTML 5输入类型=日期时间元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我在 PHP 中有一个 unix 时间戳 (int).我想在 HTML5 日期时间输入元素中以一种很好的方式显示这个值.我希望能够让用户以一种漂亮的方式看到这个值,并对其进行编辑.有什么好的方法可以做到这一点,还是我在自欺欺人,我将不得不对大量的字符串操作大惊小怪?

I have a unix timestamp (int) in PHP. I want to display this value in a nice manner in the HTML5 datetime input element. I would like to be able to have users see this value in a nice presentable manner, as well as edit it. Is there any nice way of doing this, or am I fooling myself and I am going to have to fuss around with lots of string manipulation?

推荐答案

HTML5 Input time 是这样的:1985-04-12T23:20:50.52

你可以像这样在 PHP 中做到这一点:

You can do that in PHP like this :

echo date("Y-m-dTH:i:s");

输出

2012-10-02T19:12:49

带有时间戳的 HTML

HTML with Timestamp

<input type="datetime"  value="<?php echo date("Y-m-dTH:i:s",$timestamp); ?>"/>

这篇关于PHP时间戳到HTML 5输入类型=日期时间元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

PHP实现DeepL翻译API调用
DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以...
2025-08-20 php开发问题
168

PHP通过phpspreadsheet导入Excel日期数据处理方法
PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的...
2024-10-23 php开发问题
287

mediatemple - 无法使用 codeigniter 发送电子邮件
mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)...
2024-08-23 php开发问题
11

Laravel Gmail 配置错误
Laravel Gmail Configuration Error(Laravel Gmail 配置错误)...
2024-08-23 php开发问题
16

将 PHPMailer 用于 SMTP 的问题
Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)...
2024-08-23 php开发问题
4

关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题
Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)...
2024-08-23 php开发问题
17