curl_getdate.md (4338B)
1 --- 2 c: Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al. 3 SPDX-License-Identifier: curl 4 Title: curl_getdate 5 Section: 3 6 Source: libcurl 7 See-also: 8 - CURLOPT_TIMECONDITION (3) 9 - CURLOPT_TIMEVALUE (3) 10 - curl_easy_escape (3) 11 - curl_easy_unescape (3) 12 Protocol: 13 - All 14 Added-in: 7.1 15 --- 16 17 # NAME 18 19 curl_getdate - convert date string to number of seconds 20 21 # SYNOPSIS 22 23 ~~~c 24 #include <curl/curl.h> 25 26 time_t curl_getdate(const char *datestring, const time_t *now); 27 ~~~ 28 29 # DESCRIPTION 30 31 curl_getdate(3) returns the number of seconds since the Epoch, January 32 1st 1970 00:00:00 in the UTC time zone, for the date and time that the 33 *datestring* parameter specifies. The *now* parameter is not used, 34 pass a NULL there. 35 36 This function works with valid dates and does not always detect and reject 37 wrong dates, such as February 30. 38 39 # PARSING DATES AND TIMES 40 41 A "date" is a string containing several items separated by whitespace. The 42 order of the items is immaterial. A date string may contain many flavors of 43 items: 44 45 ## calendar date items 46 47 Can be specified several ways. Month names can only be three-letter English 48 abbreviations, numbers can be zero-prefixed and the year may use 2 or 4 49 digits. Examples: 06 Nov 1994, 06-Nov-94 and Nov-94 6. 50 51 If the year appears to be below 100 (two-digit), any year after 70 is assumed 52 to be 1900 + the given year. All others are 2000 + the given year. 53 54 ## time of the day items 55 56 This string specifies the time on a given day. You must specify it with 6 57 digits with two colons: HH:MM:SS. If there is no time given in a provided date 58 string, 00:00:00 is assumed. Example: 18:19:21. 59 60 ## time zone items 61 62 Specifies international time zone. There are a few acronyms supported, but in 63 general you should instead use the specific relative time compared to 64 UTC. Supported formats include: -1200, MST, +0100. 65 66 ## day of the week items 67 68 Specifies a day of the week. Days of the week may be spelled out in full 69 (using English): 'Sunday', 'Monday', etc or they may be abbreviated to their 70 first three letters. This is usually not info that adds anything. 71 72 ## pure numbers 73 74 If a decimal number of the form YYYYMMDD appears, then YYYY is read as the 75 year, MM as the month number and DD as the day of the month, for the specified 76 calendar date. 77 78 # %PROTOCOLS% 79 80 # EXAMPLE 81 82 ~~~c 83 int main(void) 84 { 85 time_t t; 86 t = curl_getdate("Sun, 06 Nov 1994 08:49:37 GMT", NULL); 87 t = curl_getdate("Sunday, 06-Nov-94 08:49:37 GMT", NULL); 88 t = curl_getdate("Sun Nov 6 08:49:37 1994", NULL); 89 t = curl_getdate("06 Nov 1994 08:49:37 GMT", NULL); 90 t = curl_getdate("06-Nov-94 08:49:37 GMT", NULL); 91 t = curl_getdate("Nov 6 08:49:37 1994", NULL); 92 t = curl_getdate("06 Nov 1994 08:49:37", NULL); 93 t = curl_getdate("06-Nov-94 08:49:37", NULL); 94 t = curl_getdate("1994 Nov 6 08:49:37", NULL); 95 t = curl_getdate("GMT 08:49:37 06-Nov-94 Sunday", NULL); 96 t = curl_getdate("94 6 Nov 08:49:37", NULL); 97 t = curl_getdate("1994 Nov 6", NULL); 98 t = curl_getdate("06-Nov-94", NULL); 99 t = curl_getdate("Sun Nov 6 94", NULL); 100 t = curl_getdate("1994.Nov.6", NULL); 101 t = curl_getdate("Sun/Nov/6/94/GMT", NULL); 102 t = curl_getdate("Sun, 06 Nov 1994 08:49:37 CET", NULL); 103 t = curl_getdate("06 Nov 1994 08:49:37 EST", NULL); 104 t = curl_getdate("Sun, 12 Sep 2004 15:05:58 -0700", NULL); 105 t = curl_getdate("Sat, 11 Sep 2004 21:32:11 +0200", NULL); 106 t = curl_getdate("20040912 15:05:58 -0700", NULL); 107 t = curl_getdate("20040911 +0200", NULL); 108 } 109 ~~~ 110 111 # STANDARDS 112 113 This parser handles date formats specified in RFC 822 (including the update in 114 RFC 1123) using time zone name or time zone delta and RFC 850 (obsoleted by 115 RFC 1036) and ANSI C's *asctime()* format. 116 117 These formats are the only ones RFC 7231 says HTTP applications may use. 118 119 # %AVAILABILITY% 120 121 # RETURN VALUE 122 123 This function returns -1 when it fails to parse the date string. Otherwise it 124 returns the number of seconds as described. 125 126 On systems with a signed 32-bit time_t: if the year is larger than 2037 or 127 less than 1903, this function returns -1. 128 129 On systems with an unsigned 32-bit time_t: if the year is larger than 2106 or 130 less than 1970, this function returns -1. 131 132 On systems with 64-bit time_t: if the year is less than 1583, this function 133 returns -1. (The Gregorian calendar was first introduced 1582 so no "real" 134 dates in this way of doing dates existed before then.)