Subject: Re: Sample C/C++ code for getting and setting the time and date
To: None <Bbmillerr@aol.com>
From: Jeremy C. Reed <reed@reedmedia.net>
List: netbsd-help
Date: 10/15/2001 13:35:01
On Mon, 15 Oct 2001 Bbmillerr@aol.com wrote:

> Does anyone have any sample C/C++ source code they would be willing to share 
> demonstrating how to get the system time and date and set the system time and 
> date with daylight savings time support?  Thanks for your help.

Have a quick look at date's source code at src/bin/date/date.c (available
via NetBSD's cvsweb.)

It gets the time with time(3) and localtime(3) and displays it with
strftime(3).

It sets the time with settimeofday(2).

As for setting the time with daylight savings time support -- this is done
behind the scenes. Have a look at the ctime(3) and tzset(3) manual pages.
Commonly, you set the time using UTC and then you use /etc/localtime for
your local timezone or use TZ environment variable for other timezone
needs.

   Jeremy C. Reed
   http://www.reedmedia.net/