c++程序设计精确时间问题

来源:百度知道 编辑:UC知道 时间:2024/06/18 16:30:37
要求:定义一个表示时间的结构体,可以精确显示时、分、秒值;编一程序模拟时钟显示时间。
请问这应该怎么与电脑的时间同步?请各位高手给个代码,我是初学者

//程序一:
#include <time.h>
#include <stdio.h>

void main( void )
{
time_t ltime;

time( <ime );
printf( "The time is %s\n", ctime( <ime ) );
}

//程序二:
#include <time.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/timeb.h>
#include <string.h>

void main()
{
char tmpbuf[128], ampm[] = "AM";
time_t ltime;
struct _timeb tstruct;
struct tm *today, *gmt, xmas = { 0, 0, 12, 25, 11, 93 };

/* Set time zone from TZ environment variable. If TZ is not set,
* the operating system is queried to obtain the default value
* for the variable.
*/
_tzset();

/* Display operating system-style date and time. */
_strtime( tmpbuf );
printf( "OS time:\t\t\t\t%s\n", tmpbuf );