#include <time.h>
#include <stdio.h>
int UZGETTIM(int *date, int *time, int *msec, int *sts)
{
int ret ; /* 返回值 */
struct timespec nowtime ; /* system时刻(整数) */
struct tm *datetime ; /* 年月日时分秒豪秒 变换用 */
/*取得系统时刻 */
ret = clock_gettime(CLOCK_REALTIME, &nowtime) ;
if ( 0 != ret ){
ret = 1 ;
}
datetime = localtime(&nowtime.tv_sec) ;
date[0] = datetime->tm_year ; /* 年 */
date[1] = datetime->tm_mon ; /* 月 */
date[2] = datetime->tm_mday ; /* 日 */
time[0] = datetime->tm_hour ; /* 时 */
time[1] = datetime->tm_min ; /* 分 */
time[2] = datetime->tm_sec ; /* 秒 */
msec[0] = (int)(nowtime.tv_nsec/10000000) ; /* 豪秒 */
sts[0] = ret ;
return(ret);
}
void main(int argc, char *argv[]){
struct GETTIM {
int hour ;
int mins ;
int sec ;
int msec ;
int year ;
int month ;
int day ;
int week ;
} ;
struct GETTIM hastim ;
int sts;
UZGETTIM(&hastim.year, &hastim.hour, &hastim.msec, &sts);
printf("year : %d /n",hastim.year );
printf("month: %d /n",hastim.month);
printf("day : %d /n",hastim.day );
printf("hour : %d /n",hastim.hour );
printf("mins : %d /n",hastim.mins );
printf("sec : %d /n",hastim.sec );
printf("status : %d /n",sts );
}
/**********************************************************************/
/* int UZUGNOW(int *date) */
/* date (int[8] [o]) - */
/* 返回值 (int [o]) - 0:正常结束 */
/* <>0:异常结束 */
/**********************************************************************/
#include <time.h>
int UZUGNOW(int *date)
{
time_t t; /* time */
struct tm *tmr; /* struct time */
/* get location time */
tmr = NULL;
t = time(NULL);
if(t == -1){
return(-1);
}
tmr = localtime(&t);
if(tmr == NULL){
return(-1);
}
/* output to param */
date[0] = tmr->tm_year + 1900;
date[1] = tmr->tm_mon + 1;
date[2] = tmr->tm_mday ;
date[3] = tmr->tm_wday ;
date[4] = tmr->tm_hour;
date[5] = tmr->tm_min;
date[6] = tmr->tm_sec;
return(0);
}
void main(int argc, char *argv[])
{
int date[8];
memset(date,0,sizeof(date));
UZUGNOW(date);
printf("year: %d /n",date[0]);
printf("month: %d /n",date[1]);
printf("day : %d /n",date[2]);
printf("week : %d /n",date[3]);
printf("hour : %d /n",date[4]);
printf("min : %d /n",date[5]);
printf("sec : %d /n",date[6]);
printf("other: %d /n",date[7]);
}