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. Uml学习-用例建模简介

    用例建模简介  用例建模是UML建模的一部分,它也是UML里最基础的部分.用例建模的最主要功能就是用来表达系统的功能性需求或行为.用例图重点描述用户需求. 它描述需求.用户和主要组件之间的关系. 它不 ...

  2. 论文阅读(Xiang Bai——【CVPR2012】Detecting Texts of Arbitrary Orientations in Natural Images)

    Xiang Bai--[CVPR2012]Detecting Texts of Arbitrary Orientations in Natural Images 目录 作者和相关链接 方法概括 方法细 ...

  3. eclipse 安装activity插件

    公司做流程需要用到流程插件,之前用了bpm4 activity是基于bpm4延伸的,这里先介绍下activity 插件是如何安装的 官网资料 *Name:*Activiti BPMN 2.0 desi ...

  4. .net之工作流工程展示及代码分享(三)数据存储引擎

    数据存储引擎是本项目里比较有特色的模块. 特色一,使用接口来对应不同的数据库.数据库可以是Oracle.Sqlserver.MogoDB.甚至是XML文件.采用接口进行对应: public inter ...

  5. iOS GCD 编程小结

    一.简单介绍 1.GCD简介? 全称是Grand Central Dispatch,可译为“牛逼的中枢调度器” 纯C语言,提供了非常多强大的函数 2.GCD优势 GCD是苹果公司为多核的并行运算提出的 ...

  6. C# 自动Ping服务

    using Newtonsoft.Json; using Newtonsoft.Json.Linq; using System; using System.Collections.Generic; u ...

  7. Upnp资料整理

    系统,软件和路由器都要打开upnp功能. windows7下,分别启动 function discovery resources publication; Upnp device host; SSDp ...

  8. java socket 多线程通讯

    1.目录结构 2.Server.java 代码 package de.bvb.server; import java.net.ServerSocket; import java.net.Socket; ...

  9. php大小写转换

    1.将字符串转换成小写   strtolower();: 该函数将传入的字符串参数所有的字符都转换成小写,并以小定形式放回这个字符串.例: <?php $str = "I want T ...

  10. 浅析call和apply

    call, apply都属于Function.prototype的一个方法,它是JavaScript引擎内在实现的,因为属于Function.prototype,所以每个Function对象实例,也就 ...