CkDateTime Unicode C Reference Documentation

CkDateTime

A class for holding a date/time value, and for converting it to from many different formats. The power of this class is that the different date/time formats are implemented across many different operating systems. Many formats specific to Windows are available on Mac OS X, Linux/Unix, etc., and vice-versa. To convert a date/time from one format to another, simply set via one format, and get via another format. This is a freeware class because it is used by many commercial Chilkat components/libs.

Create/Dispose

HCkDateTimeW CkDateTimeW_Create(void);

Creates an instance of the HCkDateTimeW object and returns a handle (i.e. a "void *" pointer). The handle is passed in the 1st argument for the functions listed on this page.

void CkDateTimeW_Dispose(HCkDateTimeW handle);

Objects created by calling CkDateTimeW_Create must be freed by calling this method. A memory leak occurs if a handle is not disposed by calling this function. Also, any handle returned by a Chilkat "C" function must also be freed by the application by calling the appropriate Dispose method, such as CkDateTimeW_Dispose.

Properties

void CkDateTimeW_getDebugLogFilePath(HCkDateTimeW cHandle, HCkString retval);

void CkDateTimeW_putDebugLogFilePath(HCkDateTimeW cHandle, const wchar_t *newVal);

const wchar_t *CkDateTimeW_debugLogFilePath(HCkDateTimeW cHandle);

If set to a file path, causes each Chilkat method or property call to automatically append it's LastErrorText to the specified log file. The information is appended such that if a hang or crash occurs, it is possible to see the context in which the problem occurred, as well as a history of all Chilkat calls up to the point of the problem. The VerboseLogging property can be set to provide more detailed information.

This property is typically used for debugging the rare cases where a Chilkat method call hangs or generates an exception that halts program execution (i.e. crashes). A hang or crash should generally never happen. The typical causes of a hang are:

  1. a timeout related property was set to 0 to explicitly indicate that an infinite timeout is desired,
  2. the hang is actually a hang within an event callback (i.e. it is a hang within the application code), or
  3. there is an internal problem (bug) in the Chilkat code that causes the hang.

int CkDateTimeW_getIsDst(HCkDateTimeW cHandle);

This is the Daylight Saving Time flag. It can have one of three possible values: 1, 0, or -1. It has the value 1 if Daylight Saving Time is in effect, 0 if Daylight Saving Time is not in effect, and -1 if the information is not available.

Note: This is NOT the DST for the current system time. It is the DST that was in effect at the date value contained in this object.

void CkDateTimeW_getLastErrorHtml(HCkDateTimeW cHandle, HCkString retval);

const wchar_t *CkDateTimeW_lastErrorHtml(HCkDateTimeW cHandle);

Provides information in HTML format about the last method/property called. If a method call returns a value indicating failure, or behaves unexpectedly, examine this property to get more information.

void CkDateTimeW_getLastErrorText(HCkDateTimeW cHandle, HCkString retval);

const wchar_t *CkDateTimeW_lastErrorText(HCkDateTimeW cHandle);

Provides information in plain-text format about the last method/property called. If a method call returns a value indicating failure, or behaves unexpectedly, examine this property to get more information.

Concept of LastErrorText

LastErrorText Standard Information

void CkDateTimeW_getLastErrorXml(HCkDateTimeW cHandle, HCkString retval);

const wchar_t *CkDateTimeW_lastErrorXml(HCkDateTimeW cHandle);

Provides information in XML format about the last method/property called. If a method call returns a value indicating failure, or behaves unexpectedly, examine this property to get more information.

BOOL CkDateTimeW_getLastMethodSuccess(HCkDateTimeW cHandle);

void CkDateTimeW_putLastMethodSuccess(HCkDateTimeW cHandle, BOOL newVal);

Introduced in version 9.5.0.52

Indicate whether the last method call succeeded or failed. A value of TRUE indicates success, a value of FALSE indicates failure. This property is automatically set for method calls. It is not modified by property accesses. The property is automatically set to indicate success for the following types of method calls:

  • Any method that returns a string.
  • Any method returning a Chilkat object, binary bytes, or a date/time.
  • Any method returning a standard boolean status value where success = TRUE and failure = FALSE.
  • Any method returning an integer where failure is defined by a return value less than zero.

Note: Methods that do not fit the above requirements will always set this property equal to TRUE. For example, a method that returns no value (such as a "void" in C++) will technically always succeed.

int CkDateTimeW_getUtcOffset(HCkDateTimeW cHandle);

For the current system's timezone, returns the number of seconds offset from UTC for this date/time. The offset includes daylight savings adjustment. Local timezones west of UTC return a negative offset.

BOOL CkDateTimeW_getVerboseLogging(HCkDateTimeW cHandle);

void CkDateTimeW_putVerboseLogging(HCkDateTimeW cHandle, BOOL newVal);

If set to TRUE, then the contents of LastErrorText (or LastErrorXml, or LastErrorHtml) may contain more verbose information. The default value is FALSE. Verbose logging should only be used for debugging. The potentially large quantity of logged information may adversely affect peformance.

void CkDateTimeW_getVersion(HCkDateTimeW cHandle, HCkString retval);

const wchar_t *CkDateTimeW_version(HCkDateTimeW cHandle);

Version of the component/library, such as "9.5.0.63"

Methods

BOOL CkDateTimeW_AddDays(HCkDateTimeW cHandle, int numDays);

Adds an integer number of days to the date/time. To subtract days, pass a negative integer.

Returns TRUE for success, FALSE for failure.

BOOL CkDateTimeW_AddSeconds(HCkDateTimeW cHandle, int numSeconds);

Introduced in version 9.5.0.65

Adds an integer number of seconds to the date/time. To subtract seconds, pass a negative integer.

Returns TRUE for success, FALSE for failure.

DateTime - Add or Subtract Seconds

void CkDateTimeW_DeSerialize(HCkDateTimeW cHandle, const wchar_t *serializedDateTime);

Loads the date/time with a string having the format as produced by the Serialize method, which is a string of SPACE separated integers containing (in this order) year, month, day, hour, minutes, seconds, and a UTC flag having the value of 1/0.

int CkDateTimeW_DiffSeconds(HCkDateTimeW cHandle, HCkDateTimeW dateTimeArg);

Introduced in version 9.5.0.65

Returns the difference in seconds between the dateTimeArg and this date/time. The value returned is this object's date/time - dateTimeArg's date/time. For example, if the returned value is positive, then this object's date/time is more recent than dateTimeArg's date/time. If the return value is negative, then this object's date/time is older than dateTimeArg's date/time.

BOOL CkDateTimeW_ExpiresWithin(HCkDateTimeW cHandle, int n, const wchar_t *units);

Introduced in version 9.5.0.67

Returns TRUE if the date/time is within n seconds/minutes/hours/days of the current system date/time. Otherwise returns FALSE. The units can be "seconds", "minutes", "hours", or "days" (plural or singular).

Date/Time Expires Within N Seconds/Minutes/Hours/Days

BOOL CkDateTimeW_GetAsDateTime(HCkDateTimeW cHandle, BOOL bLocal, SYSTEMTIME * outDate);

Returns the date/time in a native format. The .NET implementation returns a .NET System.DateTime structure. The ActiveX implementation returns a Date object. The C/C++ implementation (and others) returns the date/time in a SYSTEMTIME structure. On Windows, SYSTEMTIME is defined at SYSTEMTIME. On non-Windows systems, Chilkat provides a SYSTEMTIME structure definition in SystemTime.h.

bLocal indicates whether a local or UTC time is returned.

Returns TRUE for success, FALSE for failure.

__int64 CkDateTimeW_GetAsDateTimeTicks(HCkDateTimeW cHandle, BOOL bLocal);

Returns the date/time as a 64-bit integer .NET DateTime value.

bLocal indicates whether a local or UTC time is returned.

This is a date and time expressed in the number of 100-nanosecond intervals that have elapsed since January 1, 0001 at 00:00:00.000 in the Gregorian calendar.

The DateTime value type represents dates and times with values ranging from 12:00:00 midnight, January 1, 0001 Anno Domini (Common Era) through 11:59:59 P.M., December 31, 9999 A.D. (C.E.).

Time values are measured in 100-nanosecond units called ticks, and a particular date is the number of ticks since 12:00 midnight, January 1, 0001 A.D. (C.E.) in the GregorianCalendar calendar (excluding ticks that would be added by leap seconds). For example, a ticks value of 31241376000000000L represents the date, Friday, January 01, 0100 12:00:00 midnight. A DateTime value is always expressed in the context of an explicit or default calendar.

unsigned long CkDateTimeW_GetAsDosDate(HCkDateTimeW cHandle, BOOL bLocal);

Returns the date/time as a 32-bit DOS date/time bitmask.

bLocal indicates whether a local or UTC time is returned.

The DOS date/time format is a bitmask:


			   24                16                 8                 0
	    +-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+
	    |Y|Y|Y|Y|Y|Y|Y|M| |M|M|M|D|D|D|D|D| |h|h|h|h|h|m|m|m| |m|m|m|s|s|s|s|s|
	    +-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+
	     \___________/\________/\_________/ \________/\____________/\_________/
		 year        month       day      hour       minute        second

The year is stored as an offset from 1980. Seconds are stored in two-second increments. (So if the "second" value is 15, it actually represents 30 seconds.)

BOOL CkDateTimeW_GetAsIso8601(HCkDateTimeW cHandle, const wchar_t *formatStr, BOOL bLocal, const wchar_t *outStr);

const wchar_t *CkDateTimeW_getAsIso8601(HCkDateTimeW cHandle, const wchar_t *formatStr, BOOL bLocal);

Introduced in version 9.5.0.65

Returns the date/time in a compatible ISO 8601 format according to the format specified in formatStr.. Examples of ISO 8601 formats include the following:

    YYYY-MM-DD

    YYYY-MM-DDThh:mmTZD

    YYYY-MM-DDThh:mm:ssTZD
For the date portion of these formats, YYYY is a four-digit year representation, MM is a two-digit month representation, and DD is a two-digit day representation. For the time portion, hh is the hour representation in 24-hour notation, mm is the two-digit minute representation, and ss is the two-digit second representation. A time designator T separates the date and time portions of the string, while a time zone designator TZD specifies a time zone (UTC).

bLocal indicates whether a local or UTC time is returned.

Note: The bLocal argument is interpreted as the reverse of what is intended . The problem was discovered just after releasing v9.5.0.65. It will be fixed in the next version update.

Returns TRUE for success, FALSE for failure.

DateTime - Get in ISO 8601 Compatible Format

double CkDateTimeW_GetAsOleDate(HCkDateTimeW cHandle, BOOL bLocal);

Returns the date/time in a Windows OLE "DATE" format.

bLocal indicates whether a local or UTC time is returned.

The OLE automation date format is a floating point value, counting days since midnight 30 December 1899. Hours and minutes are represented as fractional days.

BOOL CkDateTimeW_GetAsRfc822(HCkDateTimeW cHandle, BOOL bLocal, const wchar_t *outStr);

const wchar_t *CkDateTimeW_getAsRfc822(HCkDateTimeW cHandle, BOOL bLocal);

Returns the date/time as an RFC822 formatted string. (An RFC822 format string is what is found in the "Date" header field of an email.)

bLocal indicates whether a local or UTC time is returned.

Returns TRUE for success, FALSE for failure.

BOOL CkDateTimeW_GetAsSystemTime(HCkDateTimeW cHandle, BOOL bLocal, SYSTEMTIME * outSysTime);

Returns the date/time in a Windows SYSTEMTIME structure.

bLocal indicates whether the date/time returned is local or UTC.

For non-Windows systems, the SYSTEMTIME structure is defined in the SystemTime.h header provided in the Chilkat C/C++ libs distribution. The structure is defined as follows:

typedef struct _SYSTEMTIME
    {
    unsigned short wYear;
    unsigned short wMonth;
    unsigned short wDayOfWeek;
    unsigned short wDay;
    unsigned short wHour;
    unsigned short wMinute;
    unsigned short wSecond;
    unsigned short wMilliseconds;
    
    // A flag that indicates whether daylight saving time is in effect at the time described. 
    // The value is positive if daylight saving time is in effect, zero if it is not, 
    // and negative if the information is not available.
    int m_isdst;
    } 	SYSTEMTIME;

Returns TRUE for success, FALSE for failure.

BOOL CkDateTimeW_GetAsTimestamp(HCkDateTimeW cHandle, BOOL bLocal, const wchar_t *outStr);

const wchar_t *CkDateTimeW_getAsTimestamp(HCkDateTimeW cHandle, BOOL bLocal);

Introduced in version 9.5.0.58

Returns the date/time as an RFC 3339 formatted string, such as "1990-12-31T23:59:60Z". (This is an ISO 8061 format like the following: YYYY-MM-DDThh:mm:ssTZD)

bLocal indicates whether a local or UTC time is returned.

Returns TRUE for success, FALSE for failure.

void CkDateTimeW_GetAsTmStruct(HCkDateTimeW cHandle, BOOL bLocal, struct tm * tmbuf);

Returns the date/time in a Unix "struct tm" structure.

unsigned long CkDateTimeW_GetAsUnixTime(HCkDateTimeW cHandle, BOOL bLocal);

Returns the date/time as a 32-bit Unix time.

bLocal indicates whether the date/time returned is local or UTC.

Note: With this format, there is a Y2038 problem that pertains to 32-bit signed integers. There are approx 31.5 million seconds per year. The Unix time is number of seconds since the Epoch, 1970-01-01 00:00:00 +0000 (UTC). In 2012, it's 42 years since 1/1/1970, so the number of seconds is approx 1.3 billion. A 32-bit signed integer ranges from -2,147,483,648 to 2,147,483,647 Therefore, if a 32-bit signed integer is used, it turns negative in 2038.

The GetAsUnixTime64 and GetAsUnixTimeDbl methods are provided as solutions to the Y2038 problem.

(Note: The ActiveX Chilkat implementation omits methods that use 64-bit integers because there is no means for passing or returning 64-bit integers in ActiveX.)

__int64 CkDateTimeW_GetAsUnixTime64(HCkDateTimeW cHandle, BOOL bLocal);

The same as GetUnixTime, except returns the date/time as a 64-bit integer.

bLocal indicates whether a local or UTC time is returned.

double CkDateTimeW_GetAsUnixTimeDbl(HCkDateTimeW cHandle, BOOL bLocal);

The same as GetUnixTime, except returns the date/time as a double.

bLocal indicates whether a local or UTC time is returned.

BOOL CkDateTimeW_GetAsUnixTimeStr(HCkDateTimeW cHandle, BOOL bLocal, const wchar_t *outStr);

const wchar_t *CkDateTimeW_getAsUnixTimeStr(HCkDateTimeW cHandle, BOOL bLocal);

Introduced in version 9.5.0.65

Returns the time in Unix format (in seconds since the epoch: 00:00:00 UTC on 1 January 1970).

bLocal indicates whether the date/time returned is local or UTC.

Returns TRUE for success, FALSE for failure.

DateTime - Get as Unix Time String

unsigned short CkDateTimeW_GetDosDateHigh(HCkDateTimeW cHandle, BOOL bLocal);

Returns the high-order 16-bit integer of the date/time in DOS format. (See GetAsDosDate for more information.)

unsigned short CkDateTimeW_GetDosDateLow(HCkDateTimeW cHandle, BOOL bLocal);

Returns the low-order 16-bit integer of the date/time in DOS format. (See GetAsDosDate for more information.)

HCkDtObjW CkDateTimeW_GetDtObj(HCkDateTimeW cHandle, BOOL bLocal);

Introduced in version 9.5.0.47

Gets the date/time as a Chilkat "Dt" object.

Returns NULL on failure

Get Email Date/Time

BOOL CkDateTimeW_LoadTaskResult(HCkDateTimeW cHandle, HCkTaskW task);

Introduced in version 9.5.0.52

Loads the date/time from a completed asynchronous task.

Returns TRUE for success, FALSE for failure.

BOOL CkDateTimeW_OlderThan(HCkDateTimeW cHandle, int n, const wchar_t *units);

Introduced in version 9.5.0.67

Returns TRUE if the date/time is older than the current system date/time by n seconds/minutes/hours/days. Otherwise returns FALSE. The units can be "seconds", "minutes", "hours", or "days" (plural or singular).

Date/Time Older-Than N Seconds/Minutes/Hours/Days

BOOL CkDateTimeW_SaveLastError(HCkDateTimeW cHandle, const wchar_t *path);

Saves the last-error information (the contents of LastErrorXml) to an XML formatted file.

Returns TRUE for success, FALSE for failure.

BOOL CkDateTimeW_Serialize(HCkDateTimeW cHandle, const wchar_t *outStr);

const wchar_t *CkDateTimeW_serialize(HCkDateTimeW cHandle);

Serializes the date/time to a us-ascii string that can be imported at a later time via the DeSerialize method. The format of the string returned by this method is not intended to match any published standard. It is formatted to a string with SPACE separated integers containing (in this order) year, month, day, hour, minutes, seconds, and a UTC flag having the value of 1 or 0.

Returns TRUE for success, FALSE for failure.

BOOL CkDateTimeW_SetFromCurrentSystemTime(HCkDateTimeW cHandle);

Sets the date/time from the current system time.

BOOL CkDateTimeW_SetFromDateTimeTicks(HCkDateTimeW cHandle, BOOL bLocal, __int64 ticks);

Sets the date/time from a .NET DateTime value represented in ticks. See GetAsDateTimeTicks for more information.

bLocal indicates whether the passed in date/time is local or UTC.

BOOL CkDateTimeW_SetFromDosDate(HCkDateTimeW cHandle, BOOL bLocal, unsigned long t);

Sets the date/time from a 32-bit DOS date/time bitmask. See GetAsDosDate for more information.

BOOL CkDateTimeW_SetFromDosDate2(HCkDateTimeW cHandle, BOOL bLocal, unsigned short datePart, unsigned short timePart);

Sets the date/time from two 16-bit integers representing the high and low words of a 32-bit DOS date/time bitmask. See GetAsDosDate for more information.

bLocal indicates whether the passed in date/time is local or UTC.

BOOL CkDateTimeW_SetFromDtObj(HCkDateTimeW cHandle, HCkDtObjW dt);

Introduced in version 9.5.0.47

Sets the date/time from a Chilkat "Dt" object.

Returns TRUE for success, FALSE for failure.

BOOL CkDateTimeW_SetFromNtpTime(HCkDateTimeW cHandle, int ntpSeconds);

Introduced in version 9.5.0.50

Sets the date/time from a 32-bit NTP time value. ntpSeconds is the number of seconds since 00:00 (midnight) 1 January 1900 GMT.

BOOL CkDateTimeW_SetFromOleDate(HCkDateTimeW cHandle, BOOL bLocal, double dt);

Sets the date/time from a Windows OLE "DATE" value.

bLocal indicates whether the passed in date/time is local or UTC.

Note: This method was not working correctly. The problem was discovered just after releasing v9.5.0.65. It will be fixed in the next version update.

BOOL CkDateTimeW_SetFromRfc822(HCkDateTimeW cHandle, const wchar_t *rfc822Str);

Sets the date/time from an RFC822 date/time formatted string.

Returns TRUE for success, FALSE for failure.

BOOL CkDateTimeW_SetFromSystemTime(HCkDateTimeW cHandle, BOOL bLocal, SYSTEMTIME * sysTime);

Sets the date/time from a Windows SYSTEMTIME structure.

bLocal indicates whether the passed in date/time is local or UTC.

For non-Windows systems, the SYSTEMTIME structure is defined in the SystemTime.h header provided in the Chilkat C/C++ libs distribution. The structure is defined as follows:

typedef struct _SYSTEMTIME
    {
    unsigned short wYear;
    unsigned short wMonth;
    unsigned short wDayOfWeek;
    unsigned short wDay;
    unsigned short wHour;
    unsigned short wMinute;
    unsigned short wSecond;
    unsigned short wMilliseconds;
    
    // A flag that indicates whether daylight saving time is in effect at the time described. 
    // The value is positive if daylight saving time is in effect, zero if it is not, 
    // and negative if the information is not available.
    int m_isdst;
    } 	SYSTEMTIME;

BOOL CkDateTimeW_SetFromTimestamp(HCkDateTimeW cHandle, const wchar_t *timestamp);

Introduced in version 9.5.0.58

Sets the date/time from an RFC 3339 timestamp format. (such as "1990-12-31T23:59:60Z:")

(This is an ISO 8061 format like the following: YYYY-MM-DDThh:mm:ssTZD)

Returns TRUE for success, FALSE for failure.

How to Parse a TimeStamp (such as 2016-11-11T14:32:17.0908971Z)

BOOL CkDateTimeW_SetFromTmStruct(HCkDateTimeW cHandle, BOOL bLocal, struct tm * tmbuf);

Sets the date/time from a Unix "struct tm" structure.

BOOL CkDateTimeW_SetFromUnixTime(HCkDateTimeW cHandle, BOOL bLocal, unsigned long t);

Sets the date/time from a 32-bit UNIX time value. (See GetAsUnixTime for information about the Y2038 problem.)

bLocal indicates whether the passed in date/time is local or UTC.

BOOL CkDateTimeW_SetFromUnixTime64(HCkDateTimeW cHandle, BOOL bLocal, __int64 t);

The same as SetFromUnixTime, except that it uses a 64-bit integer to solve the Y2038 problem. (See GetAsUnixTime for more information about Y2038).

bLocal indicates whether the passed in date/time is local or UTC.

BOOL CkDateTimeW_SetFromUnixTimeDbl(HCkDateTimeW cHandle, BOOL bLocal, double d);

The same as SetFromUnixTime, except that it uses a double to solve the Y2038 problem. (See GetAsUnixTime for more information about Y2038).

bLocal indicates whether the passed in date/time is local or UTC.