站长资源网络编程

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

整理:jimmy2026/8/3浏览2
简介直接看代码:提醒:不要忘记了引用jquery的类库(function($) , /** * 日期 转换为 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>

上一篇:CascadeView级联组件实现思路详解(分离思想和单链表)

下一篇:Angular.js与Bootstrap相结合实现表格分页代码