栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > Web开发 > JavaScript

jquery中实现时间戳与日期相互转换

JavaScript 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

jquery中实现时间戳与日期相互转换

直接看代码:

提醒:不要忘记了引用jquery的类库

(function($) {
  $.extend({
    myTime: {
      
      CurTime: function(){
 return Date.parse(new Date())/1000;
      },
      
      DateToUnix: function(string) {
 var f = string.split(' ', 2);
 var d = (f[0] ? f[0] : '').split('-', 3);
 var t = (f[1] ? f[1] : '').split(':', 3);
 return (new Date(
     parseInt(d[0], 10) || null,
     (parseInt(d[1], 10) || 1) - 1,
     parseInt(d[2], 10) || null,
     parseInt(t[0], 10) || null,
     parseInt(t[1], 10) || null,
     parseInt(t[2], 10) || null
     )).getTime() / 1000;
      },
      
      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()+1) + "-";
 ymdhis += time.getUTCDate();
 if (isFull === true)
 {
   ymdhis += " " + time.getUTCHours() + ":";
   ymdhis += time.getUTCMinutes() + ":";
   ymdhis += time.getUTCSeconds();
 }
 return ymdhis;
      }
    }
  });
})(jQuery); 

调用方法:

复制代码 代码如下:

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/97653.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号