//DateTime -> UnixTimestamp -> DateTime 변환
//DateTime -> UnixTimestamp -> DateTime 변환
#include<stdio.h>
#include<time.h>
int GetUnixTimeT(int year, int month, int day, int hour, int minute, int second)
{
struct tm t = {0};
t.tm_year = year - 1900;
t.tm_mon = month - 1;
t.tm_mday = day;
t.tm_hour = hour;
t.tm_min = minute;
t.tm_sec = second;
return(mktime(&t));
}
int main(int argc, char *argv[])
{
time_t t = time(NULL);
struct tm tm = *localtime(&t);
int ____year = tm.tm_year + 1900;
int ____month = tm.tm_mon = month + 1;
int ____day = tm.tm_mday;
int ____hour = tm.tm_hour;
int ____minute = tm.tm_min;
int ____second = tm.tm_sec;
printf("DateTime(1):[%d-%d-%d %d:%d:%d]\n", ____year,
____month, ____day, ____hour, ____minute, ____second);
time_t baseTime = GetUnixTimeT(____year,
____month, ____day, ____hour, ____minute, ____second);
printf("UnixTimestamp:[%ld]\n", baseTime);
struct tm *tmmm = (struct tm *)localtime(&baseTime);
____year = tmmm->tm_year + 1900;
____month = tmmm->tm_mon = month + 1;
____day = tmmm->tm_mday;
____hour = tmmm->tm_hour;
____minute = tmmm->tm_min;
____second = tmmm->tm_sec;
printf("DateTime(2):[%d-%d-%d %d:%d:%d]\n", ____year,
____month, ____day, ____hour, ____minute, ____second);
return(0);
}
'c 언어 > 중급과정' 카테고리의 다른 글
컴파일과정에서 코드추가 가능(#define PIE 3.1416) (0) | 2021.08.05 |
---|---|
Console Hexa, form Hexa by c language (0) | 2021.04.25 |
Make파일이 없이 Compile & Link (0) | 2021.03.21 |
HEXA(QUICK VIEW)-WINDOW (0) | 2020.08.02 |
LINUX, struct tm *localtime_r(const time_t *timep, struct tm *result); (0) | 2019.10.31 |