设为首页 收藏本站 开启辅助访问
 找回密码
 立即注册

convertDateTime

0 2511
vancom 发表于 2019-10-13 10:13:10 |阅读模式 |复制链接
function convertDateToTS(date) {
  let tsArr = date.toISOString().split("T")
  return "\'" + tsArr[0] + " " + tsArr[1].substring(0, tsArr[1].length-1) + "\'";
  }

let date = new Date("2017-05-02 07:38:34");
console.info("0**********************");
console.info("2017-05-02 07:38:34");//2017-05-02 07:38:34
console.info("1**********************");
console.info(new Date("2017-05-02 07:38:34"));//2017-05-01T23:38:34.000Z
date.setHours(date.getHours() + 8);
console.info("2**********************");
console.info(date.setHours(date.getHours() + 8));//1493739514000
console.info("3**********************");
console.info(date);//2017-05-02T15:38:34.000Z
console.info("4**********************");
console.info( convertDateToTS(date));//'2017-05-02 15:38:34.000'


var rowdate =  ctx.request.body.Datetime;//20170502073834
var finedate =  rowdate.substring(0,4)+"-"+rowdate.substring(4,6)+"-"+rowdate.substring(6,8)+" "+rowdate.substring(8,10)+":"+rowdate.substring(10,12)+":"+rowdate.substring(12,14);

//2017-05-02 07:38:34
  var finedates = new Date(Date.parse(finedate.replace(/-/g,"/")));======new Date("2017-05-02 07:38:34")



function convertDateToTS(date) {
  let tsArr = date.toISOString().split("T")
  return "\'" + tsArr[0] + " " + tsArr[1].substring(0, tsArr[1].length-1) + "\'";
  }

var rowdate =  "20170502073834" ;//20170502073834
var finedate =  rowdate.substring(0,4)+"-"+rowdate.substring(4,6)+"-"+rowdate.substring(6,8)+" "+rowdate.substring(8,10)+":"+rowdate.substring(10,12)+":"+rowdate.substring(12,14);
console.info("a**********************");
console.info(finedate);//2017-05-02 07:38:34
var finedates = new Date(Date.parse(finedate.replace(/-/g,"/")));
console.info("b**********************");
console.info( new Date(finedate));


let date = new Date("2017-05-02 07:38:34");
console.info("0**********************");
console.info("2017-05-02 07:38:34");//2017-05-02 07:38:34
console.info("1**********************");
console.info(new Date("2017-05-02 07:38:34"));//2017-05-01T23:38:34.000Z
console.info("1.5**********************");
console.info(date.getHours());//7


console.info("2**********************");
console.info(date.setHours(date.getHours()));//1493710714000
console.info(date);
console.info(date.setHours(date.getHours() + 8));//1493739514000
console.info("3**********************");
console.info(date);//2017-05-02T15:38:34.000Z
console.info("4**********************");
console.info( convertDateToTS(date));//'2017-05-02 15:38:34.000'

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@




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(), //秒
        "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;
}

console.log((new Date()).Format("yyyy-MM-dd hh:mm:ss")); // 2018-08-02 21:22:07
console.log((new Date()).Format("yyyy-MM-dd"));
console.log((new Date()).Format("yyyy"));

let stime = new Date();

let interval = 1000;

//console.log(new Date().Format("yyyy"));
function convertDateToTS(date) {
    let tsArr = date.toISOString().split("T")
    return "\"" + tsArr[0] + " " + tsArr[1].substring(0, tsArr[1].length-1) + "\"";
}


console.log("1------------");
console.log(stime);
console.log("2------------");
console.log(stime.getMilliseconds());
console.log("3------------");
console.log(stime.getMilliseconds());
console.log(convertDateToTS(stime));
console.log(convertDateToTS(stime).split(" ")[0]);
stime.setMilliseconds(stime.getMilliseconds() + interval);

console.log(convertDateToTS(stime));

//////////////////////////////////////////////////////////////////
2019-11-18 10:13:23
2019-11-18
2019
1------------
2019-11-18T02:13:23.114Z
2------------
114
3------------
114
"2019-11-18 02:13:23.114"
"2019-11-18
"2019-11-18 02:13:24.114"

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

登录 发布 快速回复 返回顶部 返回列表