thinkPHP5.0框架安裝教程
776
2024-01-14
直接看代碼:
提醒:不要忘記了引用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] ? 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; }, /** * 時間戳轉換日期 * @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()+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>
#免責聲明#
本站[綠夏技術導航]提供的一切軟件、教程和內容信息僅限用于學習和研究目的;不得將上述內容用于商業或者非法用途,否則,一切后果請用戶自負。本站信息來自網絡收集整理,版權爭議與本站無關。您必須在下載后的24個小時之內,從您的電腦或手機中徹底刪除上述內容。如果您喜歡該程序或內容,請支持正版,購買注冊,得到更好的正版服務。我們非常重視版權問題,如有侵權請郵件[admin@lxwl520.com]與我們聯系進行刪除處理。敬請諒解!