js时间戳日期转换

    技术2022-07-10  140

    时间戳转换js工具类

    // 时间戳转换日期 function add0(m){ return m<10?'0'+m:m } /** * 时间戳转 Date 2020年6月30日20点53分 * @param timeStamp * @returns {string} */ function format(timeStamp){ var result = ""; if (timeStamp != undefined) { //timeStamp是整数,否则要parseInt转换 var time = new Date(timeStamp); var y = time.getFullYear(); var m = time.getMonth()+1; var d = time.getDate(); var h = time.getHours(); var mm = time.getMinutes(); var s = time.getSeconds(); result = y+'年'+add0(m)+'月'+add0(d)+'日'+add0(h)+'时'+add0(mm)+'分'; } return result; } /** * 时间戳转 Date 2020-06-30 20:53 * @param timeStamp * @returns {string} */ function formatToDate(timeStamp){// eg: 2020-06-30 20:53 var result = ""; if (timeStamp != undefined) { //timeStamp是整数,否则要parseInt转换 var time = new Date(timeStamp); var y = time.getFullYear(); var m = time.getMonth()+1; var d = time.getDate(); var h = time.getHours(); var mm = time.getMinutes(); var s = time.getSeconds(); result = y+'-'+add0(m)+'-'+add0(d)+' '+add0(h)+':'+add0(mm); } return result; }
    Processed: 0.053, SQL: 9