南强小屋 Design By 杰米

直接看代码:

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

(function($) {
  $.extend({
    myTime: {
      /**
       * 当前时间戳
       * @return <int>    unix时间戳(秒) 
       */
      CurTime: function(){
        return Date.parse(new Date())/1000;
      },
      /**       
       * 日期 转换为 Unix时间戳
       * @param <string> 2014-01-01 20:20:20 日期格式       
       * @return <int>    unix时间戳(秒)       
       */
      DateToUnix: function(string) {
        var f = string.split(' ', 2);
        var d = (f[0] "";
        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); 

调用方法:

复制代码 代码如下:<script>
    document.write($.myTime.DateToUnix('2016-04-12 10:49:59')+'<br>');
    document.write($.myTime.UnixToDate(1460429399));
</script>

标签:
jquery,时间戳,日期

南强小屋 Design By 杰米
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
南强小屋 Design By 杰米

评论“jquery中实现时间戳与日期相互转换”

暂无jquery中实现时间戳与日期相互转换的评论...