【发布时间】:2022-01-24 23:09:44
【问题描述】:
我有值时间戳数据库。
我想将格式输入 type="datetime-local" 从 mm-dd-yyyy --:-- 更改为 dd/mm/yyyy --:-- -- 使用 jquery 或 js 或 html 标记?
【问题讨论】:
标签: javascript php html jquery
我有值时间戳数据库。
我想将格式输入 type="datetime-local" 从 mm-dd-yyyy --:-- 更改为 dd/mm/yyyy --:-- -- 使用 jquery 或 js 或 html 标记?
【问题讨论】:
标签: javascript php html jquery
您可以使用momentJS extension 来做到这一点
function nowAsDuration(){
return moment.duration({
hours: moment().hour(),
minutes: moment().minute(),
seconds: moment().second()
});
}
$("input").on("change", function() {
var a = moment(this.value);
var b = nowAsDuration();
var c = a.add(b);
this.setAttribute("my-date", c.format( this.getAttribute("my-date-format") )
)
}).trigger("change")
input {
position: relative;
width: 250px; height: 20px;
color: white;
}
input:before {
position: absolute;
top: 3px; left: 3px;
content: attr(my-date);
display: inline-block;
color: black;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.10.3/moment.min.js"></script>
<input type="date" my-date="" my-date-format="DD/MM/YYYY, hh:mm:ss" value="2015-08-09">
【讨论】: