zoukankan      html  css  js  c++  java
  • js 的一些操作时间

    时间格式转换(1):

    Date.prototype.format = function(format) {
    var date = {
    "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+)/i.test(format)) {
    format = format.replace(RegExp.$1, (this.getFullYear() + '').substr(4 - RegExp.$1.length));
    }
    for (var k in date) {
    if (new RegExp("(" + k + ")").test(format)) {
    format = format.replace(RegExp.$1, RegExp.$1.length == 1
    ? date[k] : ("00" + date[k]).substr(("" + date[k]).length));
    }
    }
    return format;
    }
    var d = new Date().format('yyyy-MM-dd');

    时间格式转换(2):

    function tran_data(date_str){
    date_str = date_str.replace(/-/g,"/");//替换字符,变成标准格式
    var d2=new Date();//取今天的日期
    var d1 = new Date(Date.parse(date_str));
    return d1;
    }

    时间加减:

    function showdate(n)
    {
    var arr=Array();
    var uom = new Date();
    uom.setDate(uom.getDate()+n);
    arr[0]= uom.getFullYear();
    if(uom.getMonth()+1<10){
    arr[1]="0"+(uom.getMonth()+1);
    }else{
    arr[1]=uom.getMonth()+1;
    }
    arr[2]=uom.getDate();
    return arr;
    }

    时间比较

    var start_time=tran_data(start_dd); ///转换时间戳比较  tran_data 为时间格式转换(2)
    var end_time=tran_data(end_dd);

  • 相关阅读:
    Express中间件简介
    Express中间件概念
    浏览器cookie插件
    node=day7
    cookie可视化操作工具---EditThisCookie
    node之cookie和session对比
    node通过session保存登录状态
    浅谈表单同步提交和异步提交
    node.js服务端存储用户密码md5加密
    jQuery的ajax里dataType预期服务器返回数据类型
  • 原文地址:https://www.cnblogs.com/chenkg/p/3727662.html
Copyright © 2011-2022 走看看