function GetCookie(name) { var arr = document.cookie.match(new RegExp("(^| )" + name + "=([^;]*)(;|$)")); if (arr != null) return unescape(arr[2]); return null; } function getLocaleShortDateString(d) { var f = { "ar-sa": "dd/MM/yy", "bg-bg": "dd.M.yyyy", "ca-es": "dd/MM/yyyy", "zh-tw": "yyyy/M/d", "cs-cz": "d.M.yyyy", "da-dk": "dd-MM-yyyy", "de-de": "dd.MM.yyyy", "el-gr": "d/M/yyyy", "en-us": "M/d/yyyy", "fi-fi": "d.M.yyyy", "fr-fr": "dd/MM/yyyy", "he-il": "dd/MM/yyyy", "hu-hu": "yyyy. MM. dd.", "is-is": "d.M.yyyy", "it-it": "dd/MM/yyyy", "ja-jp": "yyyy/MM/dd", "ko-kr": "yyyy-MM-dd", "nl-nl": "d-M-yyyy", "nb-no": "dd.MM.yyyy", "pl-pl": "yyyy-MM-dd", "pt-br": "d/M/yyyy", "ro-ro": "dd.MM.yyyy", "ru-ru": "dd.MM.yyyy", "hr-hr": "d.M.yyyy", "sk-sk": "d. M. yyyy", "sq-al": "yyyy-MM-dd", "sv-se": "yyyy-MM-dd", "th-th": "d/M/yyyy", "tr-tr": "dd.MM.yyyy", "ur-pk": "dd/MM/yyyy", "id-id": "dd/MM/yyyy", "uk-ua": "dd.MM.yyyy", "be-by": "dd.MM.yyyy", "sl-si": "d.M.yyyy", "et-ee": "d.MM.yyyy", "lv-lv": "yyyy.MM.dd.", "lt-lt": "yyyy.MM.dd", "fa-ir": "MM/dd/yyyy", "vi-vn": "dd/MM/yyyy", "hy-aM": "dd.MM.yyyy", "az-latn-az": "dd.MM.yyyy", "eu-es": "yyyy/MM/dd", "mk-mk": "dd.MM.yyyy", "af-za": "yyyy/MM/dd", "ka-ge": "dd.MM.yyyy", "fo-fo": "dd-MM-yyyy", "hi-in": "dd-MM-yyyy", "ms-My": "dd/MM/yyyy", "kk-kz": "dd.MM.yyyy", "ky-kg": "dd.MM.yy", "sw-ke": "M/d/yyyy", "uz-latn-uz": "dd/MM yyyy", "tt-ru": "dd.MM.yyyy", "pa-in": "dd-MM-yy", "gu-in": "dd-MM-yy", "ta-in": "dd-MM-yyyy", "te-in": "dd-MM-yy", "kn-in": "dd-MM-yy", "mr-in": "dd-MM-yyyy", "sa-in": "dd-MM-yyyy", "mn-mn": "yy.MM.dd", "gl-es": "dd/MM/yy", "kok-in": "dd-MM-yyyy", "syr-sy": "dd/MM/yyyy", "dv-Mv": "dd/MM/yy", "ar-iq": "dd/MM/yyyy", "zh-cn": "yyyy-M-d", "de-ch": "dd.MM.yyyy", "en-gb": "dd/MM/yyyy", "es-Mx": "dd/MM/yyyy", "fr-be": "d/MM/yyyy", "it-ch": "dd.MM.yyyy", "nl-be": "d/MM/yyyy", "nn-no": "dd.MM.yyyy", "pt-pt": "dd-MM-yyyy", "sr-latn-cs": "d.M.yyyy", "sv-fi": "d.M.yyyy", "az-cyrl-az": "dd.MM.yyyy", "ms-bn": "dd/MM/yyyy", "uz-cyrl-uz": "dd.MM.yyyy", "ar-eg": "dd/MM/yyyy", "zh-hk": "d/M/yyyy", "de-at": "dd.MM.yyyy", "en-au": "d/MM/yyyy", "es-es": "dd/MM/yyyy", "fr-ca": "yyyy-MM-dd", "sr-cyrl-cs": "d.M.yyyy", "ar-ly": "dd/MM/yyyy", "zh-sg": "d/M/yyyy", "de-lu": "dd.MM.yyyy", "en-ca": "dd/MM/yyyy", "es-gt": "dd/MM/yyyy", "fr-ch": "dd.MM.yyyy", "ar-dz": "dd-MM-yyyy", "zh-mo": "d/M/yyyy", "de-li": "dd.MM.yyyy", "en-nz": "d/MM/yyyy", "es-cr": "dd/MM/yyyy", "fr-lu": "dd/MM/yyyy", "ar-ma": "dd-MM-yyyy", "en-ie": "dd/MM/yyyy", "es-pa": "MM/dd/yyyy", "fr-mc": "dd/MM/yyyy", "ar-tn": "dd-MM-yyyy", "en-za": "yyyy/MM/dd", "es-do": "dd/MM/yyyy", "ar-om": "dd/MM/yyyy", "en-jm": "dd/MM/yyyy", "es-ve": "dd/MM/yyyy", "ar-ye": "dd/MM/yyyy", "en-029": "MM/dd/yyyy", "es-co": "dd/MM/yyyy", "ar-sy": "dd/MM/yyyy", "en-bz": "dd/MM/yyyy", "es-pe": "dd/MM/yyyy", "ar-jo": "dd/MM/yyyy", "en-tt": "dd/MM/yyyy", "es-ar": "dd/MM/yyyy", "ar-lb": "dd/MM/yyyy", "en-zw": "M/d/yyyy", "es-ec": "dd/MM/yyyy", "ar-kw": "dd/MM/yyyy", "en-ph": "M/d/yyyy", "es-cl": "dd-MM-yyyy", "ar-ae": "dd/MM/yyyy", "es-uy": "dd/MM/yyyy", "ar-bh": "dd/MM/yyyy", "es-py": "dd/MM/yyyy", "ar-qa": "dd/MM/yyyy", "es-bo": "dd/MM/yyyy", "es-sv": "dd/MM/yyyy", "es-hn": "dd/MM/yyyy", "es-ni": "dd/MM/yyyy", "es-pr": "dd/MM/yyyy", "aM-et": "d/M/yyyy", "tzM-latn-dz": "dd-MM-yyyy", "iu-latn-ca": "d/MM/yyyy", "sma-no": "dd.MM.yyyy", "mn-Mong-cn": "yyyy/M/d", "gd-gb": "dd/MM/yyyy", "en-my": "d/M/yyyy", "prs-af": "dd/MM/yy", "bn-bd": "dd-MM-yy", "wo-sn": "dd/MM/yyyy", "rw-rw": "M/d/yyyy", "qut-gt": "dd/MM/yyyy", "sah-ru": "MM.dd.yyyy", "gsw-fr": "dd/MM/yyyy", "co-fr": "dd/MM/yyyy", "oc-fr": "dd/MM/yyyy", "mi-nz": "dd/MM/yyyy", "ga-ie": "dd/MM/yyyy", "se-se": "yyyy-MM-dd", "br-fr": "dd/MM/yyyy", "smn-fi": "d.M.yyyy", "moh-ca": "M/d/yyyy", "arn-cl": "dd-MM-yyyy", "ii-cn": "yyyy/M/d", "dsb-de": "d. M. yyyy", "ig-ng": "d/M/yyyy", "kl-gl": "dd-MM-yyyy", "lb-lu": "dd/MM/yyyy", "ba-ru": "dd.MM.yy", "nso-za": "yyyy/MM/dd", "quz-bo": "dd/MM/yyyy", "yo-ng": "d/M/yyyy", "ha-latn-ng": "d/M/yyyy", "fil-ph": "M/d/yyyy", "ps-af": "dd/MM/yy", "fy-nl": "d-M-yyyy", "ne-np": "M/d/yyyy", "se-no": "dd.MM.yyyy", "iu-cans-ca": "d/M/yyyy", "sr-latn-rs": "d.M.yyyy", "si-lk": "yyyy-MM-dd", "sr-cyrl-rs": "d.M.yyyy", "lo-la": "dd/MM/yyyy", "kM-kh": "yyyy-MM-dd", "cy-gb": "dd/MM/yyyy", "bo-cn": "yyyy/M/d", "sMs-fi": "d.M.yyyy", "as-in": "dd-MM-yyyy", "ml-in": "dd-MM-yy", "en-in": "dd-MM-yyyy", "or-in": "dd-MM-yy", "bn-in": "dd-MM-yy", "tk-tm": "dd.MM.yy", "bs-latn-ba": "d.M.yyyy", "mt-Mt": "dd/MM/yyyy", "sr-cyrl-Me": "d.M.yyyy", "se-fi": "d.M.yyyy", "zu-za": "yyyy/MM/dd", "xh-za": "yyyy/MM/dd", "tn-za": "yyyy/MM/dd", "hsb-de": "d. M. yyyy", "bs-cyrl-ba": "d.M.yyyy", "tg-cyrl-tj": "dd.MM.yy", "sr-latn-ba": "d.M.yyyy", "smj-no": "dd.MM.yyyy", "rm-ch": "dd/MM/yyyy", "smj-se": "yyyy-MM-dd", "quz-ec": "dd/MM/yyyy", "quz-pe": "dd/MM/yyyy", "hr-ba": "d.M.yyyy.", "sr-latn-Me": "d.M.yyyy", "sma-se": "yyyy-MM-dd", "en-sg": "d/M/yyyy", "ug-cn": "yyyy-M-d", "sr-cyrl-ba": "d.M.yyyy", "es-us": "M/d/yyyy" }; var l = navigator.language ? navigator.language : navigator['userLanguage'], y = d.getFullYear(), m = d.getMonth() + 1, d = d.getDate(); l = l.toLowerCase(); f = (l in f) ? f[l] : "MM/dd/yyyy"; function z(s) { s = '' + s; return s.length > 1 ? s : '0' + s; } f = f.replace(/yyyy/, y); f = f.replace(/yy/, String(y).substr(2)); f = f.replace(/MM/, z(m)); f = f.replace(/M/, m); f = f.replace(/dd/, z(d)); f = f.replace(/d/, d); return f; } function getLocalShortTimeString(d) { try{ var lan = navigator.language ? navigator.language : navigator['userLanguage']; var strDate = d.toLocaleTimeString([lan], { hour: '2-digit', minute: '2-digit', second: '2-digit' }); return strDate; }catch(m){ var hh = d.getHours(); var m = d.getMinutes(); var s = d.getSeconds(); var dd = "AM"; var h = hh; if (h >= 12) { h = hh - 12; dd = "PM"; } if (h == 0) { h = 12; } m = m < 10 ? "0" + m : m; s = s < 10 ? "0" + s : s; /*h = h < 10 ? "0" + h : h;*/ return h + ":" + m + ":" + s + " " + dd; } } function ConvertToLTimeArray(strServertime) { var strTime = strServertime; strTime = strTime.replace(/(^\s*)|(\s*$)/g, ""); strTime = strTime.replace(/-/g, "/"); var servertime = new Date(strTime); if (isNaN(servertime)) { return new Array(strServertime, ''); } return ConvertToLTimeArr(servertime); } function ConvertToLTimeArr(serverDateTime) { var localUTCOffset = -(new Date().getTimezoneOffset()) * 60 * 1000; // utc-local var serverUTCOffset = GetCookie("ServerUTCDateOffset"); if (serverUTCOffset == null) { return new Array(getLocaleShortDateString(serverDateTime), getLocalShortTimeString(serverDateTime)); } else { var servertime = serverDateTime.getTime(); var localTime = new Date(servertime - serverUTCOffset + localUTCOffset); return new Array(getLocaleShortDateString(localTime), getLocalShortTimeString(localTime)); } } function ConvertToLocalDateTime(serverDateTime) { var localUTCOffset = -(new Date().getTimezoneOffset()) * 60 * 1000; // utc-local var serverUTCOffset = GetCookie("ServerUTCDateOffset"); if (serverUTCOffset == null) { return serverDateTime; } else { var servertime = serverDateTime.getTime(); var localTime = new Date(servertime - serverUTCOffset + localUTCOffset); return localTime; } } function ConvertToLTime(strServertime) { var array = ConvertToLTimeArray(strServertime); return array[0] + " " + array[1]; } function UTCConvertToLTime(strUtctime) { var localUTCOffset = -(new Date().getTimezoneOffset()) * 60 * 1000; // utc-local var strTime = strUtctime; strTime = strTime.replace(/(^\s*)|(\s*$)/g, ""); strTime = strTime.replace(/-/g, "/"); var i = strTime.indexOf("."); if (i > 0){//fix bug on Firefox. strTime = strTime.substr(0, i); } var servertime = new Date(strTime).getTime(); if (isNaN(servertime)) { return strUtctime; } var localTime = new Date(servertime + localUTCOffset); return getLocaleShortDateString(localTime) + " " + getLocalShortTimeString(localTime); } /*Convert a standard time to local date without converting*/ function ConvertToLTimeDirect(strServertime) { var localUTCOffset = -(new Date().getTimezoneOffset()) * 60 * 1000; // utc-local var serverUTCOffset = GetCookie("ServerUTCDateOffset"); var localTime; if (serverUTCOffset == null) { var strTime = strServertime; var servertime = new Date(strTime).getTime(); if (isNaN(servertime)) { return strServertime; } localTime =new Date(servertime); ; } else { var strTime = strServertime; var servertime = new Date(strTime).getTime(); if (isNaN(servertime)) { return strServertime; } localTime = new Date(servertime - serverUTCOffset + localUTCOffset); } return getLocaleShortDateString(localTime) + " " + getLocalShortTimeString(localTime); } function FormatDateTime(localTime) { return getLocaleShortDateString(localTime) + " " + getLocalShortTimeString(localTime); } $(function () { StartConvertLocalTime(); }); function StartConvertLocalTime(LocalTimeclassname) { var className = ".LocalTimeContainer"; if(LocalTimeclassname == "" || LocalTimeclassname == "undefined" || LocalTimeclassname == null){ className = ".LocalTimeContainer"; } else{ className = LocalTimeclassname; } var today = getLocaleShortDateString(new Date()); $(className).each(function () { var strTime = $(this).text(); if (strTime != "") { var arrayResult = ConvertToLTimeArray(strTime); var format = $(this).data("format"); if (format == "smart") { if (arrayResult[0] == today) { $(this).text(arrayResult[1]);//time only. } else { $(this).text(arrayResult[0]);//date only. } } else { $(this).text(arrayResult[0] + " " + arrayResult[1]); } } }); }