js中常用工具函数

JS中时间戳转日期格式(YYYY-MM-dd HH:mm:ss)

function formatUnixtimestamp (unixtimestamp){  
        var datetamp = new Date(unixtimestamp);  
        var year = 1900 + datetamp.getYear();  
        var month = "0" + (datetamp.getMonth() + 1);  
        var date = "0" + datetamp.getDate();  
        var hour = "0" + datetamp.getHours();  
        var minute = "0" + datetamp.getMinutes();  
        var second = "0" + datetamp.getSeconds();  
        return year + "-" + month.substring(month.length-2, month.length)  + "-" + date.substring(date.length-2, date.length)  
            + " " + hour.substring(hour.length-2, hour.length) + ":"  
            + minute.substring(minute.length-2, minute.length) + ":"  
            + second.substring(second.length-2, second.length);  
 }  
formatUnixtimestamp(1512115468247)

 获取所有url中参数

function getUrlParams () {
    if(location.search.slice(1)){
		return JSON.parse('{"'+location.search.slice(1).replace(/%20/g,' ').replace(/=/g,'":"').replace(/&/g,'","')+'"}'+'');
	}
	return null;
}

  

posted @ 2017-12-01 16:14  G善源  阅读(108)  评论(0编辑  收藏  举报