zoukankan      html  css  js  c++  java
  • 【原创】关于jquery实现格式化时间

    //js格式化时间,参数jsonDate可以是后台数据
    function jsonDateFormat(jsonDate) {
                try {
                    var date = new Date(parseInt(jsonDate.replace("/Date(", "").replace(")/", ""), 10));
                    var month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
                    var day = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
                    var hours = date.getHours();
                    var minutes = date.getMinutes();
                    if (minutes < 10) {
                        minutes = "0" + minutes;
                    }
                    var seconds = date.getSeconds();
                    if (seconds < 10) {
                        seconds = "0" + seconds;
                    }
                    var milliseconds = date.getMilliseconds();
                    return date.getFullYear() + "-" + month + "-" + day + " " + hours + ":" + minutes + ":" + seconds;//这里可以根据需要只显示年、月、日
                } catch (ex) {
                    return "";
                }
            }
    格式化时间


    //相关资源:js时间格式转换以及data对象总结
    http://yk1688.blog.51cto.com/2000558/413970

    本人才疏学浅,如果写的不对,欢迎园子中的朋友拍砖!

  • 相关阅读:
    CSS学习1
    三个和尚没水喝阅读笔记
    Javascript学习1

    mv 批量
    emacs 大小写转换
    too many open files
    成都定房
    有关重定向
    postgresql 数据库
  • 原文地址:https://www.cnblogs.com/duanchen/p/3612715.html
Copyright © 2011-2022 走看看