Symbian
Symbian Developer Library

SYMBIAN OS V9.4

Feedback

[Index] [Previous] [Next]

#include <time.h>
Link against: libc.lib

CLOCK_REALTIME

Interface status: externallyDefinedApi

CLOCK_REALTIME 0

Description

This clock represents the realtime clock for the system.

[Top]


CLOCK_VIRTUAL

Interface status: externallyDefinedApi

CLOCK_VIRTUAL 1

Description

This clock represents the amount of time (in seconds and nanoseconds) that the calling process has spent executing code in the user's context. It is a per-process clock. It cannot be set by the user.

[Top]


TIMER_ABSTIME

Interface status: externallyDefinedApi

TIMER_ABSTIME 0x1

Description

absolute timer

[Top]


asctime(const struct tm *)

Interface status: externallyDefinedApi

IMPORT_C char* asctime(const struct tm *);

Description

Parameters

const struct tmtm *

Refer to ctime(const time_t *)ctime(const time_t *) for the documentation

Return value

char *

See also:

[Top]


clock(void)

Interface status: externallyDefinedApi

IMPORT_C clock_t clock(void);

Description

The clock function determines the amount of processor time used since the invocation of the calling process, measured in CLOCKS_PER_SEC s of a second.

Note: the clock system call eventually calls Symbian OS call user::GetCpuTime(), which is not supported from version 8.0b, hence this api is included for build support only.

Return value

clock_tclock_t

clock is just for build support and hence returns 0.

[Top]


ctime(const time_t *)

Interface status: externallyDefinedApi

IMPORT_C char* ctime(const time_t *);

Description

The functions ctime, gmtime and localtime all take as an argument a time value representing the time in seconds since the Epoch (00:00:00 UTC, January 1, 1970); see time

The function localtime converts the time value pointed at by clock and returns a pointer to a " struct tm " (described below) which contains the broken down time information for the value after adjusting for the current time zone (and any other factors such as Daylight Saving TimeTime). TimeTime zone adjustments are performed as specified by the TZ environment variable (see the tzset function). localtime uses tzset to initialize time conversion information if tzset has not already been called by the process.

After filling in the tm structure, localtime sets the tm_isdst's Nth element of tzname to a pointer to a ASCII string that is the time zone abbreviation to be used with localtime's (return, value.);

The function gmtime similarly converts the time value without any time zone adjustment and returns a pointer to a tm structure (described below).

The ctime function adjusts the time value for the current time zone, in the same manner as localtime, and returns a pointer to a 26-character string of the form: Thu Nov 24 18:22:48 1986 \0

All the fields have constant width.

The ctime_r function provides the same functionality as ctime except the caller must provide the output buffer buf to store the result, which must be at least 26 characters long.

The localtime_r and gmtime_r functions provide the same functionality as localtime and gmtime respectively, except the caller must provide the output buffer result.

The asctime function converts the broken down time in the structure tm pointed at by *tm to the form shown in the example above.

The asctime_r function provides the same functionality as asctime except the caller provides the output buffer buf to store the result, which must be at least 26 characters long.

The functions mktime converts the broken-down time in the structure pointed to by tm into a time value with the same encoding as that of the values returned by the time function (that is, seconds from the Epoch, UTC). The mktime function interprets the input structure according to the current timezone setting (see tzset ).

The original values of the tm_wday and tm_yday components of the structure are ignored, and the original values of the other components are not restricted to their normal ranges and will be normalized if needed. For example, October 40 is changed into November 9, a tm_hour of -1 means 1 hour before midnight, tm_mday of 0 means the day preceding the current month, and tm_mon of -2 means 2 months before January of tm_year.

A positive or zero value for tm_isdst causes mktime to presume initially that summer time (for example, Daylight Saving TimeTime) is or is not in effect for the specified time.. A negative value for tm_isdst causes the mktime function to attempt to define whether summer time is in effect for the specified time. The tm_isdst and tm_gmtoff members are forced to zero by timegm.

On successful completion, the values of the tm_wday and tm_yday components of the structure are set appropriately and the other components are set to represent the specified calendar time, but with their values forced to their normal ranges: The final value of tm_mday is not set until tm_mon and tm_year are determined.

The mktime function returns the specified calendar time. If the calendar time cannot be represented, it returns -1.

The difftime function returns the difference between two calendar times, ( time1 - time0), expressed in seconds.

External declarations as well as the tm structure definition are in the

  #include <time.h> include file. The tm structure includes 

at least the following fields:

int tm_sec;        // seconds (0 - 60)
int tm_min;        // minutes (0 - 59)
int tm_hour;   // hours (0 - 23) 
int tm_mday;   // day of month (1 - 31) 
int tm_mon;        // month of year (0 - 11)
int tm_year;   // year - 1900 
int tm_wday;   // day of week (Sunday = 0)
int tm_yday;   // day of year (0 - 365) 
int tm_isdst;  // is summer time in effect? 
char *tm_zone; // abbreviation of timezone name 
long tm_gmtoff;    // offset from UTC in seconds 

The field tm_isdst is non-zero if summer time is in effect.

The field tm_gmtoff is the offset (in seconds) of the time represented from UTC, with positive values indicating east of the Prime Meridian.

Examples:

//Example usage of asctime,localtime and gmtime:
#include <time.h>
#include <stdio.h>
int main(){
        time_t t;
        struct tm *timeptr;
        char* asc_time;
        t = time (NULL); //Get current time in seconds from Epoc
        //Fill tm struct w.r.t localtime using localtime
        timeptr = localtime (&t;);
        //Use this to convert it to a string indicating time w.r.t localtime
        asc_time = asctime (timeptr);
        printf ("Time from asctime w.r.t localtime : %s", asc_time);
        //Fill tm struct w.r.t GMT using gmtime
        timeptr = gmtime (&t;);
        //Use this to convert it to a string indicating time w.r.t GMT
        asc_time = asctime (timeptr);
        printf ("Time from asctime w.r.t gmtime : %s", asc_time);
        return 0;
}

Output

Time from asctime w.r.t localtime : Thu Jun 22 10:42:27 2006
Time from asctime w.r.t gmtime : Thu Jun 22 05:12:27 2006
//Example usage of ctime,mktime:
#include <time.h>
#include <stdio.h>
int main(){
        time_t t;
        struct tm timeptr;
        char* c_time;
        //Fill the tm struct with values
        timeptr.tm_year = 2001;
        timeptr.tm_mon = 6;
        timeptr.tm_mday = 4;
        timeptr.tm_hour = 0;
        timeptr.tm_min = 0;
        timeptr.tm_sec = 1;
        timeptr.tm_isdst = -1;
        t = mktime (&timeptr;); //Call mktime to make time in seconds w.r.t epoc
        //Convert this to a string indicating time using ctime
        c_time = ctime (&t;);  
        printf ("Time from ctime : %s", c_time);
        return 0;
}

Output

Time from ctime : Thu Jan  1 05:29:59 1970
//Example usage of difftime:
#include <time.h>
#include <unistd.h>
#include <stdio.h>
int main(){
        time_t t0,t1,t2;
        //Set initial and final values
        t0 = 10;
        t1 = 20;
        t2 = difftime (t1, t0); //Find the time difference using difftime
        printf ("Result of difftime = %d", t2);
        return 0;
}

Output

Result of difftime = 10

Bugs:

Except for difftime, mktime, and the _r variants of the other functions, these functions leaves their result in an internal static object and return a pointer to that object. Subsequent calls to these function will modify the same object.

The C Standard provides no mechanism for a program to modify its current local timezone setting, and the POSIX -standard method is not reentrant. (However, thread-safe implementations are provided in the POSIX threaded environment.)

The tm_zone field of a returned tm structure points to a static array of characters, which will also be overwritten by any subsequent calls (as well as by subsequent call to tzset )

Parameters

const time_ttime_t *

Note: This description also covers the following functions - difftime(time_t,time_t)difftime(time_t,time_t) asctime(const struct tm *)asctime(const struct tm *) localtime(const time_t *)localtime(const time_t *) gmtime(const time_t *)gmtime(const time_t *) mktime(struct tm *)mktime(struct tm *) ctime_r(const time_t *,char *)ctime_r(const time_t *,char *) localtime_r(const time_t *,struct tm *)localtime_r(const time_t *,struct tm *) gmtime_r(const time_t *,struct tm *)gmtime_r(const time_t *,struct tm *) asctime_r(const struct tm *,char *)asctime_r(const struct tm *,char *)

Return value

char *

Each of these functions returns the value described, NULL, or -1 in the case of mktime if an error was detected.

See also:

[Top]


difftime(time_t,time_t)

Interface status: externallyDefinedApi

IMPORT_C double difftime(time_t, time_t);

Description

Parameters

time_ttime_t

time_ttime_t

Refer to ctime(const time_t *)ctime(const time_t *) for the documentation

Return value

double

See also:

[Top]


gmtime(const time_t *)

Interface status: externallyDefinedApi

IMPORT_C struct tm* gmtime(const time_t *);

Description

Parameters

const time_ttime_t *

Refer to ctime(const time_t *)ctime(const time_t *) for the documentation

Return value

struct tmtm *

See also:

[Top]


localtime(const time_t *)

Interface status: externallyDefinedApi

IMPORT_C struct tm* localtime(const time_t *);

Description

Parameters

const time_ttime_t *

Refer to ctime(const time_t *)ctime(const time_t *) for the documentation

Return value

struct tmtm *

See also:

[Top]


mktime(struct tm *)

Interface status: externallyDefinedApi

IMPORT_C time_t mktime(struct tm *);

Description

Parameters

struct tmtm *

Refer to ctime(const time_t *)ctime(const time_t *) for the documentation

Return value

time_ttime_t

See also:

[Top]


strftime(char *,size_t,const char *,const struct tm *)

Interface status: externallyDefinedApi

IMPORT_C size_t strftime(char *, size_t, const char *, const struct tm *);

Description

No more than maxsize characters will be placed into the array. If the total number of resulting characters, including the terminating NULL character, is not more than maxsize , strftime returns the number of characters in the array, not counting the terminating NULL. Otherwise, zero is returned and the buffer contents are indeterminate.

The conversion specifications are copied to the buffer after expansion as follows:- 
%A  is replaced by national representation of the full weekday name.  
%a  is replaced by national representation of the abbreviated weekday name.  
%B  is replaced by national representation of the full month name.  
%b  is replaced by national representation of the abbreviated month name.  
%C  is replaced by (year / 100) as decimal number; single digits are preceded by a zero.  
%c  is replaced by national representation of time and date.  
%D  is equivalent to "%m/%d/%y".  
%d  is replaced by the day of the month as a decimal number (01-31).  
%E* %O*  
  POSIX locale extensions. The sequences %Ec %EC %Ex %EX %Ey %EY %Od %Oe %OH %OI %Om %OM %OS %Ou %OU %OV %Ow %OW %Oy are supposed to provide alternate representations. 
Additionally %OB implemented to represent alternative months names (used standalone, without day mentioned). 
 
%e  is replaced by the day of month as a decimal number (1-31); single digits are preceded by a blank.  
%F  is equivalent to "%Y-%m-%d".  
%G  is replaced by a year as a decimal number with century. This year is the one that contains the greater part of the week (Monday as the first day of the week).  
%g  is replaced by the same year as in "%G", but as a decimal number without century (00-99).  
%H  is replaced by the hour (24-hour clock) as a decimal number (00-23).  
%h  the same as %b.  
%I  is replaced by the hour (12-hour clock) as a decimal number (01-12).  
%j  is replaced by the day of the year as a decimal number (001-366).  
%k  is replaced by the hour (24-hour clock) as a decimal number (0-23); single digits are preceded by a blank.  
%l  is replaced by the hour (12-hour clock) as a decimal number (1-12); single digits are preceded by a blank.  
%M  is replaced by the minute as a decimal number (00-59).  
%m  is replaced by the month as a decimal number (01-12).  
%n  is replaced by a newline.  
%O*  the same as %E*.  
%p  is replaced by national representation of either "ante meridiem" or "post meridiem" as appropriate.  
%R  is equivalent to "%H:%M".  
%r  is equivalent to "%I:%M:%S %p".  
%S  is replaced by the second as a decimal number (00-60).  
%s  is replaced by the number of seconds since the Epoch, UTC (see mktime).  
%T  is equivalent to "%H:%M:%S".  
%t  is replaced by a tab.  
%U  is replaced by the week number of the year (Sunday as the first day of the week) as a decimal number (00-53).  
%u  is replaced by the weekday (Monday as the first day of the week) as a decimal number (1-7).  
%V  is replaced by the week number of the year (Monday as the first day of the week) as a decimal number (01-53). If the week containing January 1 has four or more days in the new year, then it is week 1; otherwise it is the last week of the previous year, and the next week is week 1.  
%v  is equivalent to "%e-%b-%Y".  
%W  is replaced by the week number of the year (Monday as the first day of the week) as a decimal number (00-53).  
%w  is replaced by the weekday (Sunday as the first day of the week) as a decimal number (0-6).  
%X  is replaced by national representation of the time.  
%x  is replaced by national representation of the date.  
%Y  is replaced by the year with century as a decimal number.  
%y  is replaced by the year without century as a decimal number (00-99).  
%Z  is replaced by the time zone name.  
%z  is replaced by the time zone offset from UTC; a leading plus sign stands for east of UTC, a minus sign for west of UTC, hours and minutes follow with two digits each and no delimiter between them (common form for RFC 822 date headers).  
%+  is replaced by national representation of the date and time (the format is similar to that produced by 'date( )' function ).  
%-*  GNU libc extension. Do not do any padding when performing numerical outputs.  
%_*  GNU libc extension. Explicitly specify space for padding.  
%0*  GNU libc extension. Explicitly specify zero for padding. 
%%  is replaced by ‘%’.  

Examples:

#include <string.h>
#include <stdio.h>
#include <time.h>
#include <locale.h>
int main()
{
   struct tm tm;
   char buf[255];
   char *locale;
   locale = setlocale(LC_TIME,"en_GB.ISO-8859-1");
   if( locale != NULL)
   {
       strptime("2001-11-12 18:31:01", "%Y-%m-%d %H:%M:%S", &tm;);
       printf("sec = %d min = %d hours = %d 
Year = %d Month = %d day = %d
",\
       tm.tm_sec,tm.tm_min,tm.tm_hour,tm.tm_year,tm.tm_mon,tm.tm_mday);
       strftime(buf, sizeof(buf), "%d %B %Y %H:%M:%S", &tm;);
       puts(buf);
       strptime("Mon","%a", &tm;);
       strftime(buf, sizeof(buf), "%a", &tm;);
       puts(buf);
    }
    else
       printf("Failed to set locale
");
}

Output

sec = 1 min = 31 hours = 18
Year = 101 Month = 10 day = 12
12 November 2001 18:31:01
Mon

Parameters

char *

size_tsize_t

const char *

const struct tmtm *

The strftime function formats the information from t into the buffer s according to the string pointed to by format . The format string consists of zero or more conversion specifications and ordinary characters. All ordinary characters are copied directly into the buffer. A conversion specification consists of a percent sign "\%" and one other character.

Return value

size_tsize_t

See also:

[Top]


time(time_t *)

Interface status: externallyDefinedApi

IMPORT_C time_t time(time_t *);

Description

The time function returns the value of time in seconds since 0 hours, 0 minutes, 0 seconds, January 1, 1970, Coordinated Universal TimeTime. If an error occurs, time returns the value ( time_t)(-1) .

The return value is also stored in * p , provided that p is non-null.

Examples:

/*
 Detailed description : sample usage of time system call
 */
# 445 "d:/EPOC/release/9.4/common/generic/openenv/core/include/time.dosc" 2
int main()
{
  time_t Time ;
  if(time(&Time;) < 0 ) 
  {
    printf("Time system call failed 
") ;
    return -1 ;
  }
 printf("Time value is %u 
" , Time) ;
 return 0 ;
}

Output

Time value is 1176916948

Bugs:

Neither -isoC-99 nor -p1003.1-2001 requires time to set errno on failure; thus, it is impossible for an application to distinguish the valid time value -1 (representing the last UTC second of 1969) from the error return value.

Systems conforming to earlier versions of the C and POSIX standards (including older versions of ) did not set * p in the error case.

Parameters

time_ttime_t *

Return value

time_ttime_t

On success the value of time in seconds since the Epoch is returned. On error (time_t)(-1) is returned and errno is set appropriately.

See also:

[Top]


tzset(void)

Interface status: externallyDefinedApi

IMPORT_C void tzset(void);

Description

The tzset function initializes time conversion information used by the library routine localtime . The environment variable TZ specifies how this is done.

If TZ does not appear in the environment, the best available approximation to local wall clock time is used.

If TZ appears in the environment but its value is a null string, Coordinated Universal TimeTime ( UTC ) is used (without leap second correction).

Examples:

#include <time.h>
#include <stdio.h>
int main(){
        time_t t;
        char* c_time;
        tzset(); //Call tzset
        c_time = ctime (&t;); //Get time-string using ctime for Epoc time
        printf ("Time from ctime after tzset: %s", c_time);
        return 0;
}

Output

Time from ctime after tzset: Sun Apr  7 02:24:08 1974

See also:

[Top]


clock_getres(clockid_t,struct timespec *)

Interface status: externallyDefinedApi

IMPORT_C int clock_getres(clockid_t, struct timespec *);

Description

Parameters

clockid_tclockid_t

struct timespectimespec *

Refer to clock_gettime(clockid_t,struct timespec *)clock_gettime(clockid_t,struct timespec *) for the documentation

Return value

int

See also:

[Top]


clock_gettime(clockid_t,struct timespec *)

Interface status: externallyDefinedApi

IMPORT_C int clock_gettime(clockid_t, struct timespec *);

Description

  #include < sys/time.h > as:

The clock_gettime and clock_settime allow the calling process to retrieve or set the value used by a clock which is specified by clock_id.

The clock_id argument can be one of four values: CLOCK_REALTIME for time that increments as a wall clock should, CLOCK_MONOTONIC which increments in SI seconds, CLOCK_VIRTUAL for time that increments only when the CPU is running in user mode on behalf of the calling process, or CLOCK_PROF for time that increments when the CPU is running in user or kernel mode.

As Symbian OS exposes only 'wall clock time' at user level, only CLOCK_REALTIME is supported for all the clock-based APIs.

The structure pointed to by tp is defined in

  #include <sys/time.h> as:
struct timespec {
time_ttv_sec;/* seconds */
longtv_nsec;/* and nanoseconds */
};

The resolution (granularity) of a clock is returned by the clock_getres system call. This value is placed in a (non- 0 ) *tp.

The clock_getcpuclockid system call returns ( in *clock_id ) the clock ID of the CPU-time clock of the process specified by pid. If pid is zero, the clock ID of the CPU-time clock of the process making the call is returned.

Examples:

# 601 "d:/EPOC/release/9.4/common/generic/openenv/core/include/time.dosc" 2
# 602 "d:/EPOC/release/9.4/common/generic/openenv/core/include/time.dosc" 2
int clock_user()
{
        struct timespec tp;
        int retval;
        clockid_t clockid;
        clock_getres ( 0 , &tp;); // Call clock_getres 
        printf ("Real time-clock resolution is %d seconds and %d nanoseconds
", tp.tv_sec, tp.tv_nsec);
        clock_getcpuclockid (0 ,&clockid;); // Call clock_getcpuclockid with pid = 0
        printf ("The clock id for the current process is %d
", clockid);
        tp.tv_sec = 0;
        tp.tv_nsec = 100;
        retval = clock_settime ( 0 , &tp;); // Call clock_settime with 100ns
        printf ("clock_settime returned %d
", retval);
        clock_gettime ( 0 , &tp;); // Call clock_gettime to fill tp
        printf ("Time from real time-clock is %d seconds and %d nanoseconds
", tp.tv_sec, tp.tv_nsec);
        return 0;
}

Output

Real time-clock resolution is 0 seconds and 1000000 nanoseconds
The clock id for the current process is 0
clock_settime returned 0
Time from real time-clock is 0 seconds and 70663000 nanoseconds

Parameters

clockid_tclockid_t

struct timespectimespec *

Note: This description also covers the following functions - clock_settime(clockid_t,const struct timespec *)clock_settime(clockid_t,const struct timespec *) clock_getres(clockid_t,struct timespec *)clock_getres(clockid_t,struct timespec *) clock_getcpuclockid(pid_t,clockid_t *)clock_getcpuclockid(pid_t,clockid_t *)

Return value

int

All the above APIs return 0 on success and -1 on failure.

See also:

[Top]


clock_settime(clockid_t,const struct timespec *)

Interface status: externallyDefinedApi

IMPORT_C int clock_settime(clockid_t, const struct timespec *);

Description

Parameters

clockid_tclockid_t

const struct timespectimespec *

Refer to clock_gettime(clockid_t,struct timespec *)clock_gettime(clockid_t,struct timespec *) for the documentation

Return value

int

See also:

[Top]


nanosleep(const struct timespec *,struct timespec *)

Interface status: externallyDefinedApi

IMPORT_C int nanosleep(const struct timespec *, struct timespec *);

Description

The nanosleep system call causes the process to sleep for the specified time. Currently only microsecond sleep resolution can be obtained.

Examples:

/*
 Detailed description: Sample usage of nanosleep system call.
 */
# 677 "d:/EPOC/release/9.4/common/generic/openenv/core/include/time.dosc" 2
# 678 "d:/EPOC/release/9.4/common/generic/openenv/core/include/time.dosc" 2
int main()
{
 struct timespec tim, tim2;
   tim.tv_sec = 1;
   tim.tv_nsec = 500;
   if(nanosleep(&tim; , &tim2;) < 0 )   {
      printf("Nano sleep system call failed 
");
      return -1;
   }
   printf("Nano sleep successfull 
");
  return 0;
}

Output

Nano sleep successfull

Parameters

const struct timespectimespec *

struct timespectimespec *

Return value

int

If the nanosleep system call returns because the requested time has elapsed, the value returned will be zero. If rem is non- NULL, the timespec structure it references is updated to contain the unslept amount (the request time minus the time actually slept).

See also:

[Top]


clock_getcpuclockid(pid_t,clockid_t *)

Interface status: externallyDefinedApi

IMPORT_C int clock_getcpuclockid(pid_t, clockid_t *);

Description

Parameters

pid_tpid_t

clockid_tclockid_t *

Refer to clock_gettime(clockid_t,struct timespec *)clock_gettime(clockid_t,struct timespec *) for the documentation

Return value

int

See also:

[Top]


asctime_r(const struct tm *,char *)

Interface status: externallyDefinedApi

IMPORT_C char* asctime_r(const struct tm *, char *);

Description

Parameters

const struct tmtm *

char *

Refer to ctime(const time_t *)ctime(const time_t *) for the documentation

Return value

char *

See also:

[Top]


ctime_r(const time_t *,char *)

Interface status: externallyDefinedApi

IMPORT_C char* ctime_r(const time_t *, char *);

Description

Parameters

const time_ttime_t *

char *

Refer to ctime(const time_t *)ctime(const time_t *) for the documentation

Return value

char *

See also:

[Top]


gmtime_r(const time_t *,struct tm *)

Interface status: externallyDefinedApi

IMPORT_C struct tm* gmtime_r(const time_t *, struct tm *);

Description

Parameters

const time_ttime_t *

struct tmtm *

Refer to ctime(const time_t *)ctime(const time_t *) for the documentation

Return value

struct tmtm *

See also:

[Top]


localtime_r(const time_t *,struct tm *)

Interface status: externallyDefinedApi

IMPORT_C struct tm* localtime_r(const time_t *, struct tm *);

Description

Parameters

const time_ttime_t *

struct tmtm *

Refer to ctime(const time_t *)ctime(const time_t *) for the documentation

Return value

struct tmtm *

See also:

[Top]


strptime(const char *,const char *,struct tm *)

Interface status: externallyDefinedApi

IMPORT_C char* strptime(const char *, const char *, struct tm *);

Description

The strptime function parses the string in the buffer buf according to the string pointed to by fmt , and fills in the elements of the structure pointed to by tm . The resulting values will be relative to the local time zone. Thus, it can be considered the reverse operation of strftime .

The fmt string consists of zero or more conversion specifications and ordinary characters. All ordinary characters are matched exactly with the buffer, where white space in the fmt string will match any amount of white space in the buffer. All conversion specifications are identical to those described in strftime .

Two-digit year values, including formats %y and %D , are now interpreted as beginning at 1969 per POSIX requirements. Years 69-00 are interpreted in the 20th century (1969-2000), years 01-68 in the 21st century (2001-2068).

If the fmt string does not contain enough conversion specifications to completely specify the resulting struct tm , the unspecified members of tm are left untouched. For example, if format is "\%H:\%M:\%S", only tm_hour , tm_sec and tm_min will be modified. If time relative to today is desired, initialize the tm structure with today's date before passing it to strptime .

Examples:

#include <string.h>
#include <stdio.h>
#include <time.h>
#include <locale.h>
int main()
{
    struct tm tm;
    char buf[255];
    char *locale;
    locale = setlocale(LC_TIME,"en_GB.ISO-8859-1");
    if( locale != NULL)
    {
       strptime("2001-11-12 18:31:01", "%Y-%m-%d %H:%M:%S", &tm;);
       printf("sec = %d min = %d hours = %d 
Year = %d Month = %d day = %d
",
       tm.tm_sec,tm.tm_min,tm.tm_hour,tm.tm_year,tm.tm_mon,tm.tm_mday);
       strftime(buf, sizeof(buf), "%d %B %Y %H:%M:%S", &tm;);
       puts(buf);
       strptime("Mon","%a", &tm;);
       strftime(buf, sizeof(buf), "%a", &tm;);
       puts(buf);
    }
    else
    printf("Failed to set locale");
}

Output

sec = 1 min = 31 hours = 18
Year = 101 Month = 10 day = 12
12 November 2001 18:31:01
Mon

Bugs:

Both the %e and %l format specifiers may incorrectly scan one too many digits if the intended values comprise only a single digit and that digit is followed immediately by another digit. Both specifiers accept zero-padded values, even though they are both defined as taking unpadded values.

The %p format specifier has no effect unless it is parsed after hour-related specifiers. Specifying %l without %p will produce undefined results. Note that 12AM (ante meridiem) is taken as midnight and 12PM (post meridiem) is taken as noon.

The %U and %W format specifiers accept any value within the range 00 to 53 without validating against other values supplied (like month or day of the year, for example).

The %Z format specifier only accepts time zone abbreviations of the local time zone, or the value "GMT". This limitation is because of ambiguity due to of the over loading of time zone abbreviations. One such example is EST which is both Eastern Standard TimeTime and Eastern Australia Summer TimeTime.

The strptime function does not correctly handle multibyte characters in the fmt argument.

Parameters

const char *

const char *

struct tmtm *

Return value

char *

Upon successful completion, strptime returns the pointer to the first character in buf that has not been required to satisfy the specified conversions in fmt . It returns NULL if one of the conversions failed.

See also:


time.h Global variables