Home
Developer Resources
QNX RTOS v4
QNX RTOS v4 Knowledge Base

QNX RTOS v4 Knowledge Base

Foundry27
Foundry27
QNX RTOS v4 project
Resources

QNX RTOS v4 Knowledge Base

Title How can I translate the time specified in seconds since January 1 1970
Ref. No. QNX.000010334
Category(ies) Utilities, Development, Configuration
Issue How can I translate the time specified in seconds since January 1 1970
Solution From command line you can use the "date" utility as follows.
date -s 999888777
The return from this example will be "Fri Sep 07 14:52:57 EDT 2001"

If you would like to convert this from within code,  you can use the strftime( ) function.

#include <time.h>
size_t strftime( char* s,
                size_t maxsize,
                const char* format,
                const struct tm* timeptr );

The strftime() function formats the time in the argument timeptr into the array pointed to by the argument s, according to the format argument. The format string consists of zero or more directives and ordinary characters. A directive consists of a '%' character followed by a character that determines the substitution that's to take place. All ordinary characters are copied unchanged into the array. No more than
maxsize characters are placed in the array. the format directives %D, %h, %n, %r, %t, and %T are from POSIX.
%a Locale's abbreviated weekday name.
%A Locale's full weekday name.
%b Locale's abbreviated month name.
%B Locale's full month name.
%c Locale's appropriate date and time representation.
%d Day of the month as a decimal number (01-31).
%D Date in the format mm/dd/yy (POSIX).
%h Locale's abbreviated month name (POSIX).
%H Hour (24-hour clock) as a decimal number (00-23).
%I Hour (12-hour clock) as a decimal number (01-12).
%j Day of the year as a decimal number (001-366).
%m Month as a decimal number (01-12).
%M Minute as a decimal number (00-59).
%n Newline character (POSIX).
%p Locale's equivalent of either AM or PM.
%r 12-hour clock time (01-12) using the AM/PM notation in the format HH:MM:SS (AM|PM) (POSIX).
%S Second as a decimal number (00-59).
%t Tab character (POSIX).
%T 24-hour clock time in the format HH:MM:SS (POSIX).
%U Week number of the year as a decimal number (00-52), where Sunday is the first day of the week.
%w Weekday as a decimal number (0-6), where 0 is Sunday.
%W Week number of the year as a decimal number (00-52), where Monday is the first day of the week.
%x Locale's appropriate date representation.
%X Locale's appropriate time representation.
%y Year without century, as a decimal number (00-99).
%Y Year with century, as a decimal number.
%Z Time zone name, or no characters if no time zone exists.
%% Character %.when the %Z directive is specified, the tzset() function is called.