cpp取系统时钟

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// test.cpp : 定义控制台应用程序的入口点。
//
#pragma warning( disable : 4996 )
#include "stdafx.h"
#include "time.h"
#include "windows.h"
#include <iostream>
 
using namespace std;
 
void 取系统时间()
{
    time_t timer; //time_t实际是int64
    struct tm t; //时钟的结构体
 
    time(&timer);      //取当前时间(1970年开始的秒数)
    localtime_s(&t, &timer); //把int转为时间结构体
    std::cout << "年:" << t.tm_year + 1900 << endl;
    cout << "月:" << t.tm_mon + 1 << endl;
    cout << "日 : " << t.tm_mday << endl;//星期是从星期日开始,星期日是0
    cout << "周:" << t.tm_wday << endl;
    cout << "一年之中:" << t.tm_yday << endl;
    cout << "时 : " << t.tm_hour << endl;
    cout << "分 : " << t.tm_min << endl;
    cout << "秒 : " << t.tm_sec << endl;
    cout << "夏令时 : " << t.tm_isdst << endl;
}
 
int main()
{
    取系统时间();
 
    getchar();
    return 0;
}

  

posted @   81  阅读(18)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
历史上的今天:
2012-12-26 【收集】web取客户端IP
点击右上角即可分享
微信分享提示