(function ($) {$.extend ({myTime: {/** * current timestamp * @return <int> Unix timestamp (seconds) */curtime:function () {return date.parse (new Date ())/1000; },/** * Date converted to UNIX timestamp * @param <string> 2014-01-01 20:20:20 Date grid Type * @return <int> Unix Timestamp (SEC) */Datetounix:fu Nction (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), ten) | | 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; },/** * Timestamp conversion date * @param <int> unixtime Time stamp (sec) * @param <bool> Isfull return full time (y-m-d or y-m-d h:i:s) * @param & lt;int> TimeZone Time Zone */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);
How to use
Console.log ($.mytime.datetounix (' 2014-5-15 20:20:20 '));
Console.log ($.mytime.unixtodate (1325347200));
Js/jquery Timestamp and date conversion