js获取当前时间,并将标准日期格式转换成Long型

  • Post author:
  • Post category:其他

获取当前日期:

//获取当前时间
	var nowDate = new Date();
	var year= nowDate.getFullYear();
	var month = nowDate.getMonth()+1;
	var today = nowDate.getDate();
	var hours = nowDate.getHours();
	var minutes = nowDate.getMinutes();
	var seconds = nowDate.getSeconds();
	
	if(month >= 1 && month <=9){
		month = "0" + month;
	}
	if(today >= 1 && today <=9){
		today = "0" + today;
	}
	var currentdate = year + "-" + month + "-" + today + " " + hours + ":" +minutes + ":" +seconds;


将标准日期格式转成Long型:

var currentDateLong = new Date(currentdate.replace(new RegExp("-","gm"),"/")).getTime()     //当前时间转换成long型 


结果:

当前日期:

2017-05-10 12:52:56

转换结果:

1494391976


版权声明:本文为qq_29326717原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。