Source
static int time_unit_seconds[ZBX_TIME_UNIT_COUNT] = {0, 1, SEC_PER_MIN, SEC_PER_HOUR, SEC_PER_DAY, SEC_PER_WEEK, 0,
/*
** 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/>.
**/
/******************************************************************************
* *
* Purpose: Gets the current time. *
* *
* Return value: Time in seconds *
* *
* Comments: Time in seconds since midnight (00:00:00), *
* January 1, 1970, coordinated universal time (UTC). *
* *
******************************************************************************/
double zbx_time(void)
{
zbx_timespec_t ts;
zbx_timespec(&ts);
return (double)ts.sec + 1.0e-9 * (double)ts.ns;
}
/******************************************************************************
* *
* Purpose: Gets the current time. *
* *
* Comments: Time in seconds since midnight (00:00:00), *
* January 1, 1970, coordinated universal time (UTC). *
* *
******************************************************************************/
void zbx_timespec(zbx_timespec_t *ts)
{
static ZBX_THREAD_LOCAL zbx_timespec_t last_ts = {0, 0};
static ZBX_THREAD_LOCAL int corr = 0;
static ZBX_THREAD_LOCAL LARGE_INTEGER tickPerSecond = {0};
struct _timeb tb;
int sec_diff;
struct timeval tv;
int rc = -1;
struct timespec tp;
if (0 == tickPerSecond.QuadPart)