Skip to content

Commit 6cdcb36

Browse files
author
Colin Robertson
authored
Address MicrosoftDocs/cpp-docs/issues/484 TZNAME_MAX obsolete (MicrosoftDocs#1506)
* Address MicrosoftDocs/cpp-docs/issues/484 TZNAME_MAX obsolete * Add comments to the sample * Update tzname-max.md - Clarify how to find the equivalent information.
1 parent c4a18ea commit 6cdcb36

2 files changed

Lines changed: 54 additions & 13 deletions

File tree

docs/c-runtime-library/reference/get-tzname.md

Lines changed: 51 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: "_get_tzname | Microsoft Docs"
33
ms.custom: ""
4-
ms.date: "11/04/2016"
4+
ms.date: "10/22/2018"
55
ms.technology: ["cpp-standard-libraries"]
66
ms.topic: "reference"
77
apiname: ["_get_tzname"]
@@ -44,6 +44,14 @@ The size of the *timeZoneName* character string in bytes.
4444
*index*<br/>
4545
The index of one of the two time zone names to retrieve.
4646

47+
|*index*|Contents of *timeZoneName*|*timeZoneName* default value|
48+
|-|-|-|
49+
|0|Time zone name|"PST"|
50+
|1|Daylight standard time zone name|"PDT"|
51+
|> 1 or < 0|**errno** set to **EINVAL**|not modified|
52+
53+
Unless the values are explicitly changed during run time, the default values are "PST" and "PDT" respectively.
54+
4755
## Return Value
4856

4957
Zero if successful, otherwise an **errno** type value.
@@ -62,17 +70,51 @@ If either *timeZoneName* is **NULL**, or *sizeInBytes* is zero or less than zero
6270

6371
## Remarks
6472

65-
The **_get_tzname** function retrieves the character string representation of the 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, just the size of the string of either time zone 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.
73+
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.
6674

67-
### Index values
75+
## Example
6876

69-
|*index*|Contents of *timeZoneName*|*timeZoneName* default value|
70-
|-------------|--------------------------------|----------------------------------|
71-
|0|Time zone name|"PST"|
72-
|1|Daylight standard time zone name|"PDT"|
73-
|> 1 or < 0|**errno** set to **EINVAL**|not modified|
77+
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.
7478

75-
Unless the values are explicitly changed during run time, the default values are "PST" and "PDT" respectively. The sizes of these character arrays are governed by **TZNAME_MAX** value.
79+
```C
80+
// crt_get_tzname.c
81+
// Compile by using: cl /W4 crt_get_tzname.c
82+
#include <stdio.h>
83+
#include <time.h>
84+
#include <malloc.h>
85+
86+
enum TZINDEX {
87+
STD,
88+
DST
89+
};
90+
91+
int main()
92+
{
93+
size_t tznameSize = 0;
94+
char * tznameBuffer = NULL;
95+
96+
// Get the size of buffer required to hold DST time zone name
97+
if (_get_tzname(&tznameSize, NULL, 0, DST))
98+
return 1; // Return an error value if it failed
99+
100+
// Allocate a buffer for the name
101+
if (NULL == (tznameBuffer = (char *)(malloc(tznameSize))))
102+
return 2; // Return an error value if it failed
103+
104+
// Load the name in the buffer
105+
if (_get_tzname(&tznameSize, tznameBuffer, tznameSize, DST))
106+
return 3; // Return an error value if it failed
107+
108+
printf_s("The current Daylight standard time zone name is %s.\n", tznameBuffer);
109+
return 0;
110+
}
111+
```
112+
113+
### Output
114+
115+
```Output
116+
The current Daylight standard time zone name is PDT.
117+
```
76118

77119
## Requirements
78120

@@ -89,4 +131,3 @@ For more information, see [Compatibility](../../c-runtime-library/compatibility.
89131
[_get_daylight](get-daylight.md)<br/>
90132
[_get_dstbias](get-dstbias.md)<br/>
91133
[_get_timezone](get-timezone.md)<br/>
92-
[TZNAME_MAX](../../c-runtime-library/tzname-max.md)<br/>

docs/c-runtime-library/tzname-max.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: "TZNAME_MAX | Microsoft Docs"
33
ms.custom: ""
4-
ms.date: "11/04/2016"
4+
ms.date: "10/22/2018"
55
ms.technology: ["cpp-standard-libraries"]
66
ms.topic: "conceptual"
77
f1_keywords: ["TZNAME_MAX"]
@@ -14,7 +14,7 @@ ms.workload: ["cplusplus"]
1414
---
1515
# TZNAME_MAX
1616

17-
The maximum permissible string length for a time zone name variable.
17+
**Obsolete**. The maximum permissible string length for a time zone name variable. This macro was defined in \<limits.h> in Visual Studio 2012 and earlier versions. It is not defined in Visual Studio 2013 and later versions. To get the length required to hold the current time zone name, use [_get_tzname](../c-runtime-library/reference/get-tzname.md).
1818

1919
## Syntax
2020

@@ -26,4 +26,4 @@ The maximum permissible string length for a time zone name variable.
2626

2727
[Environmental Constants](../c-runtime-library/environmental-constants.md)<br/>
2828
[Global Constants](../c-runtime-library/global-constants.md)<br/>
29-
[_get_tzname](../c-runtime-library/reference/get-tzname.md)
29+
[_get_tzname](../c-runtime-library/reference/get-tzname.md)

0 commit comments

Comments
 (0)