JS一些常用方法的封装

过滤html标签以及nbsp等

function contentFun (dot) {
  var dotStr = "";
  if (dot) {
    dotStr = dot.replace(/<[^>]+>|&[^>]+;/g,"").trim();
    dotStr = dot.replace(/<[^>]+>/g, "");
    dotStr = dotStr.replace(/“/g, "");
    dotStr = dotStr.replace(/”/g, "");
    dotStr = dotStr.replace(/ /g, "");
  }
  return dotStr;
};

转时间戳为 yyyy-mm-dd h:m

function formateTime(unixtime){
	if(!unixtime){
    	return "/"
	}
  	var dateTime = new Date(parseInt(unixtime))
	var year = dateTime.getFullYear();
  	var month = dateTime.getMonth() + 1;
  	var day = dateTime.getDate();
  	var hour = dateTime.getHours();
  	var minute = dateTime.getMinutes();
  	var second = dateTime.getSeconds();
  	unixtime = year + '-' + ((month < 10) ? ('0' + month) : month) + '-' + ((day < 10) ? ('0' + day) : day) + ' ' + ((hour < 10) ? ('0' + hour) : hour) + ':' + ((minute < 10) ? ('0' + minute) : minute);
  	return unixtime;}

你可能感兴趣的:(js)