js中unix时间格式化为时分秒格式

/**unix时间差(秒时间差)转化*/
function unixPoorTrans(trasData){
    var hour,min,sec;/**时、分、秒*/
    var transTM = new Date();/**声明js日期变量*/
    var transedTM="";
    transTM.setTime(trasData*1000);/**初始化js日期*/
  
  /**得到时、分、秒,并重新组装时间*/ (transTM.getHours()-8) < 10 ? hour = '0' + (transTM.getHours()-8) : hour = transTM.getHours()-8; transTM.getMinutes() < 10 ? min = '0' + transTM.getMinutes() : min = transTM.getMinutes(); transTM.getSeconds() < 10 ? sec = '0' + transTM.getSeconds() : sec = transTM.getSeconds(); if(hour != '00') transedTM += hour+"小时"; if(min != '00') transedTM += min+"分"; if(sec != '00') transedTM += sec+"秒"; return transedTM; }
posted @ 2012-07-03 10:36  tangrongyue  Views(2237)  Comments(0Edit  收藏  举报