_get_tzname

Retrieves the character string representation of the time zone name or the daylight standard time zone name (DST).

Syntax

errno_t _get_tzname(
    size_t* pReturnValue,
    char* timeZoneName,
    size_t sizeInBytes,
    int index
);

Parameters

pReturnValue
The string length of timeZoneName including a null terminator.

timeZoneName
The address of a character string for the representation of the time zone name or the daylight standard time zone name (DST), depending on index.

sizeInBytes
The size of the timeZoneName character string in bytes.

index
The index of one of the two time zone names to retrieve.

index Contents of timeZoneName timeZoneName default value
0 Time zone name "PST"
1 Daylight standard time zone name "PDT"
> 1 or < 0 errno set to EINVAL not modified

Unless the values are explicitly changed during run time, the default values are "PST" and "PDT" respectively.

Return Value

Zero if successful, otherwise an errno type value.

If either timeZoneName is NULL, or sizeInBytes is zero or less than zero (but not both), an invalid parameter handler is invoked, as described in Parameter Validation. If execution is allowed to continue, this function sets errno to EINVAL and returns EINVAL.

Error Conditions

pReturnValue timeZoneName sizeInBytes index Return value Contents of timeZoneName
size of TZ name NULL 0 0 or 1 0 not modified
size of TZ name any > 0 0 or 1 0 TZ name
not modified NULL > 0 any EINVAL not modified
not modified any zero any EINVAL not modified
not modified any > 0 > 1 EINVAL not modified

Remarks

The _get_tzname function retrieves the character string representation of the current time zone name or the daylight standard time zone name (DST) into the address of timeZoneName depending on the index value, along with the size of the string in pReturnValue. If timeZoneName is NULL and sizeInBytes is zero, the size of the string required to hold the specified time zone and a terminating null in bytes is returned in pReturnValue. The index values must be either 0 for standard time zone or 1 for daylight standard time zone; any other values of index have undetermined results.

Example

This sample calls _get_tzname to get the required buffer size to display the current Daylight standard time zone name, allocates a buffer of that size, calls _get_tzname again to load the name in the buffer, and prints it to the console.

// crt_get_tzname.c
// Compile by using: cl /W4 crt_get_tzname.c
#include <stdio.h>
#include <time.h>
#include <malloc.h>

enum TZINDEX {
    STD,
    DST
};

int main()
{
    size_t tznameSize = 0;
    char * tznameBuffer = NULL;

    // Get the size of buffer required to hold DST time zone name
    if (_get_tzname(&tznameSize, NULL, 0, DST))
        return 1;    // Return an error value if it failed

    // Allocate a buffer for the name
    if (NULL == (tznameBuffer = (char *)(malloc(tznameSize))))
        return 2;    // Return an error value if it failed

    // Load the name in the buffer
    if (_get_tzname(&tznameSize, tznameBuffer, tznameSize, DST))
        return 3;    // Return an error value if it failed

    printf_s("The current Daylight standard time zone name is %s.\n", tznameBuffer);
    return 0;
}

Output

The current Daylight standard time zone name is PDT.

Requirements

Routine Required header
_get_tzname <time.h>

For more information, see Compatibility.

See also

Time Management
errno, _doserrno, _sys_errlist, and _sys_nerr
_get_daylight
_get_dstbias
_get_timezone