ChorusOS 5.0 Application Developer's Guide

Using the Date Service

This section demonstrates how the date service is handled on ChorusOS systems. The following example uses the ctime() function to convert the system date to a standard character string.


Example 12-2 Using the Date Service

#include <stdio.h>
#include <chorus.h>
#include <date/chDate.h>
int result;
KnTimeVal resol, time1, time2;
int main( )
{
    result = univTimeGetRes(&resolution);
    if (result != K_OK)
        printf("error on univTimeGetRes: %s\n", strSysError(result));
    else
        printf("resolution: %d sec, %d nano\n", resol.tmSec, resol.tmNSec);
    result = univTime (&time1);
    if (result != K_OK)
        printf("error on univTime: %s\n", strSysError(result));
    printf("time is: %d seconds, %d nanoseconds\n", time1.tmSec,
            time1.tmNSec);
    printf(" ==> %s\n", ctime(&time1));
    time2.tmSec = 40000000; time2.tmNSec = 0;
    result = univTimeSet(&time1, &time2);
    if (result != K_OK)
        printf("error on univTimeSet: %s\n", strSysError(result));
    result = univTime (&time1);
    if (result != K_OK)
        printf("error on univTime: %s\n", strSysError(result));
    printf("time is: %d seconds, %d nanoseconds\n", time1.tmSec,
            time1.tmNSec);
    printf(" ==> %s\n", ctime(&time1));
}

This program produces the following output:


neon date_s.r
started aid = 2
resolution: 0 sec, 10000000 nano
time is: 947179797 seconds, 590000000 nanoseconds
		Thu Jan 6 17:29:57 2000
time is: 40000000 seconds, 10000000 nanoseconds
		Thu Apr 8 23:06:40 1971