ftime()

Get the current time

Synopsis:

#include <sys/timeb.h>

int ftime( struct timeb * timeptr );

Since:

BlackBerry 10.0.0

Arguments:

timeptr
A pointer to a timeb structure where the function can store the current time; see below.

Library:

libc

Use the -l c option to qcc to link against this library. This library is usually included automatically.

Description:

The ftime() function stores the current time in the timeptr structure. The timeb structure contains the following fields:

time_t time
Time, in seconds, since the Unix Epoch, 00:00:00 January 1, 1970 Coordinated Universal Time (UTC).
unsigned short millitm
Milliseconds.
short timezone
Difference in minutes of the timezone from UTC.
short dstflag
Nonzero if in daylight savings time.

Returns:

0
Success.
-1
An error occurred ( errno is set).

Examples:

#include <stdio.h>
#include <time.h>
#include <sys/timeb.h>
#include <stdlib.h>

int main( void )
{
    struct timeb timebuf;
    char *now;

    ftime( &timebuf );
    now = ctime( &timebuf.time );
    
    /* Note that we're cutting "now" off
     * after 19 characters to avoid the
     * \n that ctime() appends to the
     * formatted time string.
     */

    printf( "The time is %.19s.%hu\n", 
            now, timebuf.millitm );

    return EXIT_SUCCESS;
}

Produces output similar to the following:

The time is Mon Jul 05 15:58:42.870

Classification:

POSIX 1003.1 XSI

Safety:  
Cancellation point No
Interrupt handler No
Signal handler Yes
Thread Yes

Last modified: 2014-06-24



Got questions about leaving a comment? Get answers from our Disqus FAQ.

comments powered by Disqus