wcsptime() — Convert Wide Character String to Date/Time

Format

#include <wchar.h>
wchar_t *wcsptime(const wchar_t *buf, const wchar_t *format, struct tm *tm);

Language Level

Extended

Threadsafe

Yes

Locale Sensitive

The behavior of this function might be affected by the LC_UNI_CTYPE, LC_UNI_TIME, and LC_UNI_TOD categories of the current locale. This function is only available when LOCALETYPE(*LOCALEUTF) is specified on the compilation command. For more information, see Understanding CCSIDs and Locales.

Wide Character Function

See Wide Characters for more information.

Description

The wcsptime() function converts the wide character string pointed to by buf to values that are stored in the tm structure pointed to by tm, using the format specified by format. This function is equivalent to strptime(), except that it uses wide characters.

See strptime() — Convert String to Date/Time for a description of the format string.

Return Value

On successful completion, the wcsptime() function returns a pointer to the character following the last wide character parsed. Otherwise, a null pointer is returned. The value of errno may be set to ECONVERT (conversion error).

Example

#include <stdio.h>
#include <time.h>
#include <wchar.h>

int main(void)
{
   wchar_t buf[100];
   time_t t;
   struct tm *timeptr,result;

   t = time(NULL);
   timeptr = localtime(&t);
   wcsftime(buf, 100, L"%a %m/%d/%Y %r", timeptr);

   if (wcsptime(buf, L"%a %m/%d/%Y %r", &result) == NULL)
      printf("\nwcsptime failed\n");
   else
   {
      printf("tm_hour:  %d\n",result.tm_hour);
      printf("tm_min:  %d\n",result.tm_min);
      printf("tm_sec:  %d\n",result.tm_sec);
      printf("tm_mon:  %d\n",result.tm_mon);
      printf("tm_mday:  %d\n",result.tm_mday);
      printf("tm_year:  %d\n",result.tm_year);
      printf("tm_yday:  %d\n",result.tm_yday);
      printf("tm_wday:  %d\n",result.tm_wday);
   }

   return 0;
}

/************************************************************
     The output should be similar to:
      
      tm_hour:  14
      tm_min:  25
      tm_sec:  34
      tm_mon:  7
      tm_mday:  19
      tm_year:  103
      tm_yday:  230
      tm_wday:  2
************************************************************/

Related Information