【问题标题】:How to change format of input type="datetime-local" to dd/mm/yyyy --:-- -- jquery or html?如何将 input type="datetime-local" 的格式更改为 dd/mm/yyyy --:-- -- jquery 或 html?
【发布时间】:2022-01-24 23:09:44
【问题描述】:

我有值时间戳数据库。

我想将格式输入 type="datetime-local" 从 mm-dd-yyyy --:-- 更改为 dd/mm/yyyy --:-- -- 使用 jquery 或 js 或 html 标记?

【问题讨论】:

标签: javascript php html jquery


【解决方案1】:

您可以使用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">

【讨论】:

  • 除了使用momentJS扩展之外还有什么办法
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-02-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多