JS常用的function集合

  1.把字符串转为日期格式

       (1) var str ='2012-08-12 23:13:15';str = str.replace(/-/g,"/");var date = new Date(str );

(2)  function strToDate(str) {

 var tempStrs = str.split(" ");
var dateStrs = tempStrs[0].split("-");
var year = parseInt(dateStrs[0], 10);
var month = parseInt(dateStrs[1], 10) - 1;
var day = parseInt(dateStrs[2], 10);
var timeStrs = tempStrs[1].split("-");
var hour = parseInt(timeStrs [0], 10);
var minute = parseInt(timeStrs[1], 10) - 1;
var second = parseInt(timeStrs[2], 10);
var date = new Date(year, month, day, hour, minute, second);
return date;
}

 

posted @ 2015-03-05 09:17  Coderlhx  阅读(218)  评论(0编辑  收藏  举报