Skip to content

Commit 45cfccf

Browse files
authored
Merge pull request #4483 from TylerMSFT/github4107
draft to address github #4107
2 parents 078ce2a + c8ba2ad commit 45cfccf

File tree

1 file changed

+52
-34
lines changed

1 file changed

+52
-34
lines changed
Lines changed: 52 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
---
22
description: "Learn more about: _get_tzname"
33
title: "_get_tzname"
4-
ms.date: "4/2/2020"
4+
ms.date: 08/23/2022
55
api_name: ["_get_tzname", "_o__get_tzname"]
66
api_location: ["msvcrt.dll", "msvcr80.dll", "msvcr90.dll", "msvcr100.dll", "msvcr100_clr0400.dll", "msvcr110.dll", "msvcr110_clr0400.dll", "msvcr120.dll", "msvcr120_clr0400.dll", "ucrtbase.dll", "api-ms-win-crt-time-l1-1-0.dll", "api-ms-win-crt-private-l1-1-0.dll"]
77
api_type: ["DLLExport"]
88
topic_type: ["apiref"]
99
f1_keywords: ["_get_tzname", "get_tzname"]
1010
helpviewer_keywords: ["_get_tzname function", "time zones", "get_tzname function"]
11-
ms.assetid: df0065ff-095f-4237-832c-2fe9ab913875
1211
---
13-
# _get_tzname
12+
# `_get_tzname`
1413

15-
Retrieves the character string representation of the time zone name or the daylight standard time zone name (DST).
14+
Retrieves the character string representation of the time zone name or the daylight standard time (DST) zone name.
1615

1716
## Syntax
1817

@@ -27,51 +26,62 @@ errno_t _get_tzname(
2726

2827
### Parameters
2928

30-
*pReturnValue*<br/>
31-
The string length of *timeZoneName* including a null terminator.
29+
*`pReturnValue`*\
30+
The string length of *`timeZoneName`* including a `NULL` terminator.
3231

33-
*timeZoneName*<br/>
34-
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*.
32+
*`timeZoneName`*\
33+
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`*.
3534

36-
*sizeInBytes*<br/>
37-
The size of the *timeZoneName* character string in bytes.
35+
*`sizeInBytes`*\
36+
The size of the *`timeZoneName`* character string in bytes.
3837

39-
*index*<br/>
40-
The index of one of the two time zone names to retrieve.
38+
*`index`*\
39+
The *`index`* of one of the two time zone names to retrieve.
4140

42-
|*index*|Contents of *timeZoneName*|*timeZoneName* default value|
41+
|*`index`*|Contents of *`timeZoneName`*|*`timeZoneName`* default value|
4342
|-|-|-|
44-
|0|Time zone name|"PST"|
45-
|1|Daylight standard time zone name|"PDT"|
46-
|> 1 or < 0|**errno** set to **EINVAL**|not modified|
43+
|0|Time zone name|`"PST"`|
44+
|1|Daylight standard time zone name|`"PDT"`|
45+
|> 1 or < 0|**`errno`** set to `EINVAL`|not modified|
4746

48-
Unless the values are explicitly changed during run time, the default values are "PST" and "PDT" respectively.
47+
Unless explicitly updated during runtime, `"PST"` is returned for the standard time zone and `"PDT"` for the daylight standard time zone. For more information, see the [Remarks](#remarks).
48+
49+
The time zone string isn't guaranteed to be the same between OS releases. Official time zone names can and do change.
4950

5051
## Return Value
5152

52-
Zero if successful, otherwise an **errno** type value.
53+
Zero if successful, otherwise an **`errno`** type value.
5354

54-
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](../../c-runtime-library/parameter-validation.md). If execution is allowed to continue, this function sets **errno** to **EINVAL** and returns **EINVAL**.
55+
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](../../c-runtime-library/parameter-validation.md). If execution is allowed to continue, this function sets **`errno`** to `EINVAL` and returns `EINVAL`.
5556

5657
### Error Conditions
5758

58-
|*pReturnValue*|*timeZoneName*|*sizeInBytes*|*index*|Return value|Contents of *timeZoneName*|
59+
|*`pReturnValue`*|*`timeZoneName`*|*`sizeInBytes`*|*`index`*|Return value|Contents of *`timeZoneName`*|
5960
|--------------------|--------------------|-------------------|-------------|------------------|--------------------------------|
60-
|size of TZ name|**NULL**|0|0 or 1|0|not modified|
61+
|size of TZ name|`NULL`|0|0 or 1|0|not modified|
6162
|size of TZ name|any|> 0|0 or 1|0|TZ name|
62-
|not modified|**NULL**|> 0|any|**EINVAL**|not modified|
63-
|not modified|any|zero|any|**EINVAL**|not modified|
64-
|not modified|any|> 0|> 1|**EINVAL**|not modified|
63+
|not modified|`NULL`|> 0|any|`EINVAL`|not modified|
64+
|not modified|any|zero|any|`EINVAL`|not modified|
65+
|not modified|any|> 0|> 1|`EINVAL`|not modified|
6566

6667
## Remarks
6768

68-
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.
69+
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`*.
70+
71+
The *`index`* values must be either 0 for standard time zone or 1 for daylight standard time zone; any other values have undetermined results.
72+
73+
By default, `"PST"` is returned for the standard time zone and `"PDT"` for the daylight standard time zone. The true time zone name is updated the first time it's needed by a function that requires time zone information, such as [`strftime`](strftime-wcsftime-strftime-l-wcsftime-l.md), [`ftime`](ftime-ftime32-ftime64.md), [`ftime_s`](ftime-s-ftime32-s-ftime64-s.md), [`mktime`](mktime-mktime32-mktime64.md), [`localtime`](localtime-localtime32-localtime64.md), and others. If a function that doesn't require time zone information isn't called prior to calling `_get_tzname`, the default values are returned unless you first explicitly update them with one of the functions just mentioned, or a call to [`tzset()`](tzset.md). Also, if the `TZ` environment variable is set, it takes precedence over the time zone name reported by the OS. Even in this case, one of the functions mentioned above must be called before `_get_tzname` is called or the default time zone value will be returned. For more information about the `TZ` environment variable and the CRT, see [`_tzset`](tzset.md).
74+
75+
> [!WARNING]
76+
> The time zone string is not guaranteed to be the same between OS releases. Official time zone names can and do change.
6977
7078
By default, this function's global state is scoped to the application. To change this, see [Global state in the CRT](../global-state.md).
7179

7280
## Example
7381

74-
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.
82+
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.
83+
84+
It also calls `_tzset()` to cause the OS to update the time zone information before calling `_get_tzname()`. Otherwise, the default values are used.
7585

7686
```C
7787
// crt_get_tzname.c
@@ -80,7 +90,7 @@ This sample calls **_get_tzname** to get the required buffer size to display the
8090
#include <time.h>
8191
#include <malloc.h>
8292

83-
enum TZINDEX {
93+
enum TZindex {
8494
STD,
8595
DST
8696
};
@@ -90,17 +100,25 @@ int main()
90100
size_t tznameSize = 0;
91101
char * tznameBuffer = NULL;
92102

103+
_tzset(); // Update the time zone information
104+
93105
// Get the size of buffer required to hold DST time zone name
94106
if (_get_tzname(&tznameSize, NULL, 0, DST))
107+
{
95108
return 1; // Return an error value if it failed
109+
}
96110

97111
// Allocate a buffer for the name
98112
if (NULL == (tznameBuffer = (char *)(malloc(tznameSize))))
113+
{
99114
return 2; // Return an error value if it failed
115+
}
100116

101117
// Load the name in the buffer
102118
if (_get_tzname(&tznameSize, tznameBuffer, tznameSize, DST))
119+
{
103120
return 3; // Return an error value if it failed
121+
}
104122

105123
printf_s("The current Daylight standard time zone name is %s.\n", tznameBuffer);
106124
return 0;
@@ -110,21 +128,21 @@ int main()
110128
### Output
111129

112130
```Output
113-
The current Daylight standard time zone name is PDT.
131+
The current Daylight standard time zone name is Pacific Daylight Time.
114132
```
115133

116134
## Requirements
117135

118136
|Routine|Required header|
119137
|-------------|---------------------|
120-
|**_get_tzname**|\<time.h>|
138+
|`_get_tzname`|`<time.h>`|
121139

122140
For more information, see [Compatibility](../../c-runtime-library/compatibility.md).
123141

124142
## See also
125143

126-
[Time Management](../../c-runtime-library/time-management.md)<br/>
127-
[errno, _doserrno, _sys_errlist, and _sys_nerr](../../c-runtime-library/errno-doserrno-sys-errlist-and-sys-nerr.md)<br/>
128-
[_get_daylight](get-daylight.md)<br/>
129-
[_get_dstbias](get-dstbias.md)<br/>
130-
[_get_timezone](get-timezone.md)<br/>
144+
[Time Management](../../c-runtime-library/time-management.md)\
145+
[`errno`, `_doserrno`, `_sys_errlist`, and `_sys_nerr`](../../c-runtime-library/errno-doserrno-sys-errlist-and-sys-nerr.md)\
146+
[`_get_daylight`](get-daylight.md)\
147+
[`_get_dstbias`](get-dstbias.md)\
148+
[`_get_timezone`](get-timezone.md)

0 commit comments

Comments
 (0)