#include <stdio.h>
#include <time.h>
#include <windows.h>
int main()
{
SYSTEMTIME s;
GetLocalTime(&s);
printf("It's %d/%d/%d %02d:%02d:%02d now.", s.wYear, s.wMonth, s.wDay, s.wHour, s.wMinute, s.wMinute);
printf("\nAnd it's the %d day of a week.", s.wDayOfWeek);
struct tm *ptr;
time_t lt;
__int64 w(1617669906);
lt = (time_t)w;
printf("The Calendar Time now is %d\n", lt);
ptr = localtime(<);
printf("hour:%d minute:%d second:%d \n ", ptr->tm_hour, ptr->tm_min, ptr->tm_sec);
lt = time(NULL);
printf("The Calendar Time now is %d\n", lt);
ptr = localtime(<);
printf("hour:%d minute:%d second:%d \n ", ptr->tm_hour, ptr->tm_min, ptr->tm_sec);
return 0;
}
SYSTEMTIME和time_t的用法例子
最新推荐文章于 2025-02-01 16:14:08 发布
这个C++程序使用了<time.h>和<Windows.h>库来获取并打印本地时间,包括年、月、日、小时、分钟和秒。同时,它也展示了如何将时间戳转换为可读的时间格式。程序首先获取当前的本地时间,然后将其转换为结构体,并输出到控制台。接着,程序通过time()函数获取当前时间戳,再次进行格式化输出。
1383

被折叠的 条评论
为什么被折叠?



