JSFiddle - React, Tailwind, and code Playground

by Faisal Pathan

HTML

<!DOCTYPE html>
<html>

<head>
        <meta charset="utf-8" />
        <title>Convert json date to date format in jQuery</title>
        <script src="http://code.jquery.com/jquery-2.1.4.min.js"></script>
        <script src="date.format.js"></script>
        <script>
                var date = "\/Date(1297246301973)\/";
                var nowDate = new Date(parseInt(date.substr(6)));
                var result = "";
                result += nowDate.format("ddd mmm dd yyyy HH:MM:ss") + " : ddd mmm dd yyyy HH:MM:ss <br/>";
                result += nowDate.format("dd/mm/yyyy") + " : dd/mm/yyyy <br/>";
                result += nowDate.format("m/d/yy") + " : m/d/yy <br/>";
                result += nowDate.format("mmm d, yyyy") + " : mmm d, yyyy <br/>";
                result += nowDate.format("mmmm d, yyyy") + " : mmmm d, yyyy <br/>";
                result += nowDate.format("dddd, mmmm d, yyyy") + " : dddd, mmmm d, yyyy <br/>";
                result += nowDate.format("yyyy-mm-dd'T'HH:MM:ss") + " : yyyy-mm-dd'T'HH:MM:ss <br/>";
                result += nowDate.format("UTC:yyyy-mm-dd'T'HH:MM:ss'Z'") + " : UTC:yyyy-mm-dd'T'HH:MM:ss'Z'<br/>";

                $(function() {
                        $("#lblDate").html(result);
                });
        </script>
</head>

<body>
        <h1>Convert json date to date format in jQuery</h1>
        <label id="lblDate" style="color:green;"></label>
</body>

</html>

CSS

/* Put your css in here */

h1 {
  color: red;
}

JavaScript

/*
 * Anil Singh
 */

var dateFormat = function() {
        var token = /d{1,4}|m{1,4}|yy(?:yy)?|([HhMsTt])\1?|[LloSZ]|"[^"]*"|'[^']*'/g,
                timezone = /\b(?:[PMCEA][SDP]T|(?:Pacific|Mountain|Central|Eastern|Atlantic) (?:Standard|Daylight|Prevailing) Time|(?:GMT|UTC)(?:[-+]\d{4})?)\b/g,
                timezoneClip = /[^-+\dA-Z]/g,
                pad = function(val, len) {
                        val = String(val);
                        len = len || 2;
                        while (val.length < len) val = "0" + val;
                        return val;
                };

        // Regexes and supporting functions are cached through closure
        return function(date, mask, utc) {
                var dF = dateFormat;

                // You can't provide utc if you skip other args (use the "UTC:" mask prefix)
                if (arguments.length == 1 && Object.prototype.toString.call(date) == "[object String]" && !/\d/.test(date)) {
                        mask = date;
                        date = undefined;
                }

                // Passing date through Date applies Date.parse, if necessary
                date = date ? new Date(date) : new Date;
                if (isNaN(date)) throw SyntaxError("invalid date");

                mask = String(dF.masks[mask] || mask || dF.masks["default"]);

                // Allow setting the utc argument via the mask
                if (mask.slice(0, 4) == "UTC:") {
                        mask = mask.slice(4);
                        utc = true;
                }

                var _ = utc ? "getUTC" : "get",
                        d = date[_ + "Date"](),
                        D = date[_ + "Day"](),
                        m = date[_ + "Month"](),
                        y = date[_ + "FullYear"](),
                        H = date[_ + "Hours"](),
                        M = date[_ + "Minutes"](),
                        s = date[_ + "Seconds"](),
                        L = date[_ +...