gettimeofday
OS/리눅스 & 유닉스 2012. 2. 4. 09:21#include <stdio.h>
#include <sys/time.h>
#include <time.h>
#include <unistd.h>
E_SMS_ERRCODE __FC_Sms_SetCurrentTime(
T_SMS_SENDPARAM * pParam,
struct tm *ptm)
{
struct timeval tv;
struct tm *ptm;
long milliseconds;
long microseconds;
gettimeofday(&tv, NULL);
ptm = localtime (&tv.tv_sec);
pParam->year = ptm->tm_year + 1900;
pParam->month = ptm->tm_mon +1;
pParam->day = ptm->tm_mday;
pParam->hour = ptm->tm_hour;
pParam->minute = ptm->tm_min;
pParam->second = ptm->tm_sec;
// Get microseconds
microseconds = tv.tv_usec;
// Compute milliseconds from microseconds
milliseconds = tv.tv_usec / 1000;
return SMS_RET_OK;
}
void print_time ()
{
struct timeval tv;
struct tm* ptm;
char time_string[40];
long milliseconds;
/* Obtain the time of day, and convert it to a tm struct. */
gettimeofday (&tv, NULL);
ptm = localtime (&tv.tv_sec);
/* Format the date and time, down to a single second. */
strftime (time_string, sizeof (time_string), "%Y-%m-%d %H:%M:%S", ptm);
/* Compute milliseconds from microseconds. */
milliseconds = tv.tv_usec / 1000;
/* Print the formatted time, in seconds, followed by a decimal point
and the milliseconds. */
printf ("%s.%03ld\n", time_string, milliseconds);
}[출처] gettimeofday => 년, 월, 일, 시, 분, 초|작성자 롯데샌드
'OS > 리눅스 & 유닉스' 카테고리의 다른 글
vmstat (0) | 2012.02.09 |
---|---|
SAR(System Activity Reporter) (0) | 2012.02.09 |
쓰레드, 시그널2 (0) | 2012.02.02 |
쓰레드, 시그널 (0) | 2012.02.02 |
signal set 관련 함수 (sigemptyset, sigaddset, sigdelset, sigprocmask) (0) | 2012.02.01 |