yy-mm-dd hh:mm:ss转换时间戳

yy-mm-dd hh:mm:ss转换时间戳 及 时间戳 转yy-mm-dd hh:mm:ss

时间戳 转yy-mm-dd hh:mm:ss

                  var now = new Date();   //标准时间
                    var year = now.getFullYear(); //得到年份
                    var month = now.getMonth(); //得到月份
                    var date = now.getDate(); //得到日期
                    month = month + 1;
                    if (month < 10) month = "0" + month;
                    if (date < 10) date = "0" + date;
                    var time = "";
                    time = year + "-" + month + "-" + date
                    time = time.substring(0, 19);
                    time = time.replace(/-/g, '/');//转化成yyyy-MM-ss
                    var time = new Date(time).getTime();//转化成时间戳
                    // alert( time+"当前")  yyyy-mm-dd

字符串时间转成时间戳

  var date = this.reportDateStart;
 
                    date = date.substring(0, 19);
 
                    date = date.replace(/-/g, '/'); //yy-mm-dd hh:mm:ss 必须转换成yy/mm/dd hh:mm:ss  不然ios上会出现new Date(date).getTime() 值为undefind
 
                   //var timestamp = new Date(date).getTime();
 
                   //var timestamp = +new Date(date);

你可能感兴趣的:(前端,正则表达式,javascript)