ILE C/C++ Run-Time Library Functions


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.

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.

Note:
This function is available only when LOCALETYPE(*LOCALEUTF) is specified on the compilation command.

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 that uses wcsptime()

#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


[ Top of Page | Previous Page | Next Page | Table of Contents | Index ]