js時間戳記和時間格式之間的轉換

來源:互聯網
上載者:User

標籤: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時間戳記和時間格式之間的轉換

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.