当前位置: 代码迷 >> Web前端 >> jquery 日期与时间戳的变换
  详细解决方案

jquery 日期与时间戳的变换

热度:102   发布时间:2012-11-23 00:03:43.0
jquery 日期与时间戳的转换
(function($) {
$.extend({
  myTime: {
    /**              
    * 日期 转换为 Unix时间戳
* @param <int> year    年              
* @param <int> month   月              
* @param <int> day     日              
* @param <int> hour    时              
* @param <int> minute  分              
* @param <int> second  秒              
* @return <int>        unix时间戳(秒)              
*/            
DateToUnix: function(year, month, day, hour, minute, second){                 
var oDate =
new Date(Date.UTC(parseInt(year),                         
parseInt(month), parseInt(day),                         
parseInt(hour), parseInt(minute),                         
parseInt(second)
)                 
);                 
return (oDate.getTime()/1000);
},             
/**              
* 时间戳转换日期              
* @param <int> unixTime    待时间戳(秒)              
* @param <bool> isFull    返回完整时间(Y-m-d 或者 Y-m-d H:i:s)              
* @param <int>  timeZone   时区              
*/
UnixToDate: function(unixTime, isFull, timeZone){                 
if (typeof(timeZone) == 'number')                 
{                     
unixTime = parseInt(unixTime) + parseInt(timeZone) * 60 * 60;                 
}
var time = new Date(unixTime*1000);                 
var ymdhis = "";
ymdhis += time.getUTCFullYear() + "-";                 
ymdhis += time.getUTCMonth() + "-";                 
ymdhis += time.getUTCDate();
if ( isFull === true )                 
{                     
ymdhis += " " + time.getUTCHours() + ":";                     
ymdhis += time.getUTCMinutes() + ":";                     
ymdhis += time.getUTCSeconds();                 
}
return ymdhis;             
}         
}     
}); 
})(jQuery);
  相关解决方案