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 time1 = new Date().Format("yyyy-MM-dd");
            var time2 = new Date().Format("hh:mm:ss");

js 时间格式化 代码的更多相关文章

  1. js 时间格式化 (兼容safari)

    js 时间格式化,兼容IE8和safari浏览器. function formatDate(date, fmt, near, type) { var dateStr = date; if (!date ...

  2. js时间格式化函数,支持Unix时间戳

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/ ...

  3. 时间戳显示为多少分钟前,多少天前的JS处理,JS时间格式化,时间戳的转换

    var dateDiff = function (timestamp) { // 补全为13位 var arrTimestamp = (timestamp + '').split(''); for ( ...

  4. 表单序列化json字符串和js时间格式化

    js时间格式化 new Date().format("时间格式") Date.prototype.format = function(fmt) { var o = {        ...

  5. js时间格式化

    const formatDate = timestamp => { const date = new Date(timestamp); const m = date.getMonth() + 1 ...

  6. js时间格式化(yy年MM月dd日 hh:mm)

    //时间格式化 Date.prototype.format = function (format) { var o = { "M+": this.getMonth() + 1, / ...

  7. js 时间格式化 -- 时间加减实现

    时间格式化的方法: Date.prototype.Format = function (fmt) { //author: meizz var o = { "M+": this.ge ...

  8. JS 时间格式化函数

    //时间格式化函数 Date.prototype.format = function (format) { var o = { "M+": this.getMonth() + 1, ...

  9. js时间格式化函数(兼容IOS)

    * 时间格式化 * @param {Object} dateObj 时间对象 * @param {String} fmt 格式化字符串 */ dateFormat(dateObj, fmt) { le ...

随机推荐

  1. grunt 入门学习

    前端工作流,Grunt上手指南 Posted@2013-04-20 7:15 a.m. CategoriesGrunt ,  javascript 我想先花点时间回忆一下作为一个前端需要做的工作(Lo ...

  2. (二)ADS1.2的安装教程以及使用 调试 (不会 AXD 调试工具)

    安装教程: 参考百度 http://jingyan.baidu.com/article/cdddd41c7db85253cb00e1ae.html 具体使用看: 杨铸的那本书(嵌入式底层软件驱动开发) ...

  3. NODEJS 在Centos下面的自动启动

    直接上代码 #!/bin/sh ## chkconfig: 345 99 10# description: Node.js /home/cekimy/index.js# . /etc/rc.d/ini ...

  4. opencv的学习笔记5

    总结原博文中的一些边缘检测算子和滤波器.(Canny算子,  Sobel算子,  Laplace算子以及Scharr滤波器) 首先,一般的边缘检测包括三个步骤: 1)滤波:边缘检测的算法主要是基于图像 ...

  5. curl 模拟请求get/post

    $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=wx24a0ef ...

  6. python学习笔记之类class(第六天)

         参考文档:              1.金角大王博客:http://www.cnblogs.com/alex3714/articles/5188179.html               ...

  7. String.Join的巧用

    String.Join大大的方便了我们拼接字符串的处理. 1.普通用法:指定元素间的拼接符号 var ids = new List<int>(); for (int i = 0; i &l ...

  8. qt qml fuzzyPanel 毛玻璃效果

    毛玻璃效果,用qml来写代码真是简短,大爱qml:) [下载地址]http://download.csdn.net/detail/surfsky/8426641 [核心代码] Rectangle{ c ...

  9. Linux中tcpdump的编译和使用

    tcpdump官网:http://www.tcpdump.org/ 转载于:http://www.cnblogs.com/hzl6255/p/6147985.html 目录 1. 介绍 2. 编译 2 ...

  10. SuiteScript > Script Queue Monitor (Beta)

    Share Note: Installing and Accessing the Script Queue Monitor Script Queue Monitor (Beta) is availab ...