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. Windows Phone 七、XML序列化

    DataContractSerializer对象 public class Person { public int Id { get; set; } public string Name { get; ...

  2. Shopex4.85商派2014年商业模板和商业插件共600多套仅售600元送分销王2代SEO排名神具。

    这批shopex商业插 件+模板都是本人从官方模板网站收购.高价.交换.以及收藏得来.本人因现实工作太忙不得不转手出售这批源代码,限时低价出售给和我一样从事shopex 系统网店电子商务的兄弟姐妹们, ...

  3. sdk、jdk、jre、jvm、jdt、cdt分别都是什么东西

    1.sdk是什么 sdk,全称是 software development kit 中文译为软件开发工具包.kit 在英文中有工具箱,设备包,成套工具的意思. 从名字就可以看出sdk作为一个工具箱,其 ...

  4. Select For update语句浅析 (转)

    Select … for update语句是我们经常使用手工加锁语句.通常情况下,select语句是不会对数据加锁,妨碍影响其他的DML和DDL操作.同时,在多版本一致读机制的支持下,select语句 ...

  5. New Concept English 1-10

    Lesson 10 The loss of Titanic The great ship, Titanic, sailed for New York from Southampton on April ...

  6. 机器人操作臂运动学入门一--D-H参数标定

    最近重新学习机器人方面的知识,想到一年以前在学校选修<机器人学技术基础>这门课的时候,老师虽然讲机器人的各个方面的知识都讲到了,但只是浮光绿影的的提到,并没有真正讲到深处,我的理解也没有更 ...

  7. easyui 日期控件清空值

    最近用了Easyui的日期控件datebox,项目中要将选中值清空,于是就研究了一下. 1,调用方法清空 $('#yourId').combo('setText',''); 2,更改js文件 从官网下 ...

  8. Spring MVC视图解析器

    Spring MVC提供的视图解析器使用ViewResolver进行视图解析,实现浏览器中渲染模型.ViewResolver能够解析JSP.Velocity模板.FreeMarker模板和XSLT等多 ...

  9. socket.io中emit和on的用法

    socket.emit('action');表示发送了一个action命令,命令是字符串的,在另一端接收时,可以这么写: socket.on('action',function(){...});soc ...

  10. Javascript学习笔记:闭包题解(3)

    代码: function assignHandler(){ var element=document.getElementById('someElementId'); element.onclick= ...