標籤:datetime format 時間戳記 blog date() span eth for style
//時間戳記轉換成日期時間2014-8-8 下午11:40:20function formatDate(ns){ return new Date(parseInt(ns) * 1000).toLocaleString().replace(/年|月/g, "-").replace(/日/g, " ");}//時間戳記轉換成八位日期2014-5-5 function userDate(uData){ var myDate = new Date(uData*1000); var year = myDate.getFullYear(); var month = myDate.getMonth() + 1; var day = myDate.getDate(); return year + ‘-‘ + month + ‘-‘ + day;}//時間戳記轉換成四位時間10:10 function userTime(uTime){ var myDate = new Date(uTime*1000); var hours = myDate.getHours(); var minutes = myDate.getMinutes(); return hours + ‘:‘ + minutes;}//時間戳記轉換成四位時間10:10:00function userTime(uTime){ var myDate = new Date(uTime*1000); var hours = myDate.getHours(); var minutes = myDate.getMinutes(); var second = myDate.getSeconds(); return hours + ‘:‘ + minutes + ‘:‘ + second;}//定時提醒設定的時間傳入 (2014,05,15)返回成2014-01-21function setDate(year,month,day){ return year + ‘-‘ + month + ‘-‘ + day; }//定時提醒設定的時間傳入 (01:02)返回成01:01:00function setTime(hour,minute){ return hour + ‘:‘ + minute+ ‘:00‘;}//時間格式2014-02-02 14:10:00改成時間戳記function js_strto_time(str_time){ var new_str = str_time.replace(/:/g,"-"); new_str = new_str.replace(/ /g,"-"); var arr = new_str.split("-"); var datum = new Date(Date.UTC(arr[0],arr[1]-1,arr[2],arr[3]-8,arr[4],arr[5])); return strtotime = datum.getTime()/1000;}//時間戳記改成時間格式2014-12-12 下午01:10function js_date_time(unixtime){ var timestr = new Date(parseInt(unixtime) * 1000); var datetime = timestr.toLocaleString().replace(/年|月/g,"-").replace(/日/g," "); return datetime;}
js時間戳記和時間格式之間的轉換