zoukankan      html  css  js  c++  java
  • js 时间格式化 -- 时间加减实现

    时间格式化的方法:

     1      Date.prototype.Format = function (fmt) { //author: meizz 
     2             var o = {
     3                 "M+": this.getMonth() + 1, //月份 
     4                 "d+": this.getDate(), //
     5                 "h+": this.getHours(), //小时 
     6                 "m+": this.getMinutes(), //
     7                 "s+": this.getSeconds(), //
     8                 "q+": Math.floor((this.getMonth() + 3) / 3), //季度 
     9                 "S": this.getMilliseconds() //毫秒 
    10             };
    11             if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
    12             for (var k in o)
    13                 if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
    14             return fmt;
    15         }
    1 <script type="text/javascript">
    2   var mydate=new Date();
    3   document.write("当前时间:"+mydate+"<br>");
    4   mydate.setTime(mydate.getTime() + 60 * 60 * 1000);
    5   document.write("推迟一小时时间:" + mydate);
    6 </script>
     1 function dateTest()
     2         {
     3             var d = new Date("2016-01-01 16:00:01");
     4             //alert(d.getDate() + " -- " + d.getDay());
     5             //alert(d.getTime());
     6             //设定的时间加上一个小时
     7             var end = new Date(d.getTime() + 60 * 60 * 1000);
     8             alert(end);
     9             alert(end.Format("yyyy-MM-dd hh:mm:ss"));
    10         }
  • 相关阅读:
    Python 字符串
    python 元组用法
    python 字典用法
    环境配置
    桥式整流以及电容作用
    三角序列的正交性
    MDS
    ISOMAP
    randperm
    数据库~Mysql里的Explain说明
  • 原文地址:https://www.cnblogs.com/yougmi/p/5145748.html
Copyright © 2011-2022 走看看