获取当前时间

来源:互联网 发布:淘宝基金如何赎回 编辑:程序博客网 时间:2024/06/05 20:10

在windows下和在linux下获取当前时间

static void get_current_time(char *str)

{
#ifdef _WIN32
SYSTEMTIME st;


GetLocalTime(&st);//GetSystemTime


sprintf(str,"%04d-%02d-%02d %02d:%02d:%02d.%03d",
st.wYear,
st.wMonth,
st.wDay,
st.wHour,
st.wMinute,
st.wSecond,
st.wMilliseconds);
#else
struct tm *now;
time_t second;

time(&second);


now=localtime(&second);


sprintf(str,"%04d-%02d-%02d %02d:%02d:%02d",
now->tm_year+1900,
now->tm_mon+1,
now->tm_mday,
now->tm_hour,
now->tm_min,
now->tm_sec);
#endif
}
原创粉丝点击