zoukankan      html  css  js  c++  java
  • js日期格式化

    1.拼凑

         var myDate = new Date();
                var weekday=new Array(7)
                weekday[0]="星期日"
                weekday[1]="星期一"
                weekday[2]="星期二"
                weekday[3]="星期三"
                weekday[4]="星期四"
                weekday[5]="星期五"
                weekday[6]="星期六"
                var currDate = myDate.getYear()+1900+"年"+myDate.getMonth()+1+"月"+myDate.getDate()+"日 "+weekday[myDate.getDay()];
                document.getElementById("currDate").innerHTML = currDate;

        效果:2016年01月13日 星期三

    2.自定义

        Date.prototype.Format = function (fmt) { //author: meizz
                    var o = {
                        "M+": this.getMonth() + 1, //月份
                        "d+": this.getDate(), //日
                        "h+": this.getHours(), //小时
                        "m+": this.getMinutes(), //分
                        "s+": this.getSeconds(), //秒
                        "q+": Math.floor((this.getMonth() + 3) / 3), //季度
                        "S": this.getMilliseconds() //毫秒
                    };
                    if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
                    for (var k in o)
                    if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
                    return fmt;
                }
                var currDate = new Date().Format("yyyy-MM-dd hh:mm:ss");
                document.getElementById("currDate").innerHTML = currDate;

        效果:2016-01-13 14:58:51

    currDate

  • 相关阅读:
    spring异常
    springboot+mybatis
    mybatis初识
    模板引擎Dot
    mysql数据库操作
    1. 安装Oracle,配置环境 2. 实现查询From子句 3. 实现查询where子句 4. 实现查询order by子句
    (1)Set集合 (2)Map集合 (3)异常机制
    (1)网络编程的常识 (2)基于tcp协议的编程模型 (3)tcp协议和udp协议的比较 (4)基于udp协议的编程模型
    (1)线程的常用方法 (2)线程的同步机制 (3)网络编程的常识
    (1)I/O流 (2)线程
  • 原文地址:https://www.cnblogs.com/luoxiaolei/p/5127336.html
Copyright © 2011-2022 走看看