2.1.8.28 okutil_datetime_convert


Description

Convert Unix timestamp to or from Julian date.

Syntax

double okutil_datetime_convert(double dVal, double dTimeZone, int nYear, bool bToJulian)

Parameters

dVal
[input] if bToJulian is true, it is Unix time (UTC) where 0 is the beginning of nYear; if bToJulian is false, it is the Julian date to be converted.
dTimeZone
[input] Julian date time zone, e.g. UTC+08:00 is +8.00.
nYear
[input] the beginning of nYear represents Unix time (UTC) = 0.
bToJulian
[input] when it is true, dVal is Unix time (UTC) where 0 is the beginning of nYear and it is converted to Julian date in timezone dTimeZone and returned; when it is false, dVal is the Julian date in timezone dTimeZone and it is converted to Unix time (UTC) where 0 is the beginning of nYear and returned.

Return

the converted value

Examples

EX1

void ts_test()
{
	// convert Unix time 3419562484 (from the year 1900 instead of 1970) to Julian date in Beijing Time UTC+08:00

	double dTS = 3419562484.0;
	double dTimezone = +08.00;
	int nYear = 1900;
	double dJD = okutil_datetime_convert(dTS, dTimezone, nYear, true);

	char str[128];
	date_to_str_custom(dJD, "yyyy'-'MM'-'dd'T'HH':'mm':'ss+08:00", str);
	out_str(str);  // "2008-05-12T14:28:04+08:00"
}

Remark

See Also

Header to Included

origin.h

Reference