Source
return appendZero(dt) + ' ' + shortMn[mnth] + ' ' + yr + ' ' + appendZero(hrs) + ':' + appendZero(mnts);
/*
** Copyright (C) 2001-2025 Zabbix SIA
**
** This program is free software: you can redistribute it and/or modify it under the terms of
** the GNU Affero General Public License as published by the Free Software Foundation, version 3.
**
** This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
** without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
** See the GNU Affero General Public License for more details.
**
** You should have received a copy of the GNU Affero General Public License along with this program.
** If not, see <https://www.gnu.org/licenses/>.
**/
var CDate = function () {
this.clientDate = (arguments.length > 0)
? new Date(arguments[0])
: new Date();
this.calcTZdiff(this.clientDate.getTime());
this.serverDate = new Date(this.clientDate.getTime() - this.tzDiff * 1000);
};
CDate.prototype = {
server: 0, // getTime uses clients :0, or servers time :1
tzDiff: 0, // server and client TZ diff
clientDate: null, // clients(JS, Browser) date object
serverDate: null, // servers(PHP, Unix) date object
calcTZdiff: function(time) {
if (time === undefined) {
time = new Date().getTime();
}
const timestamp = Object.keys(PHP_TZ_OFFSETS).reverse().find((ts) => ts * 1000 <= time);
this.tzDiff = this.clientDate.getTimezoneOffset() * -60 - PHP_TZ_OFFSETS[timestamp];
},
/**
* Formats date according given format. Uses server timezone.
* Supported formats: 'd M Y H:i', 'j. M Y G:i', 'Y/m/d H:i', 'Y-m-d H:i', 'Y-m-d H:i:s', 'Y-m-d h:i:s A',
* 'Y-m-d','H:i:s', 'H:i', 'M jS, Y h:i A', 'Y M d H:i', 'd.m.Y H:i' and 'd m Y H i'
* Format 'd m Y H i' is also accepted but used internally for date input fields.
*
* @param format PHP style date format limited to supported formats
*
* @return string|bool human readable date or false if unsupported format given
*/
format: function(format) {
const shortMn = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
const dt = this.getDate();
const mnth = this.getMonth();
const yr = this.getFullYear();
const hrs = this.getHours();
const mnts = this.getMinutes();
const sec = this.getSeconds();
const ampm = (hrs < 12) ? 'AM' : 'PM';
const ampmhrs = appendZero((hrs + 11) % 12 + 1);
/**
* Append date suffix according to English rules e.g., 3 becomes 3rd.
*