首页 > 编程语言 >C++编写Time类显示系统时间

C++编写Time类显示系统时间

时间:2022-11-18 19:06:40浏览次数:49  
标签:now int time year C++ tm Time 编写 include


编写Time类,要求:
(1) 包含年、月、日、时、分、秒的信息。
(2) 构造函数将类的对象初始化为系统当前时间(使用头文件time.h中的time函数。)
(3) 能按照标准格式输出对象表示的时间。
编译器 VC6.0

class ONE_1  
{
public:
ONE_1();
int year;
int month;
int day;
int hour;
int minute;
int second;
virtual ~ONE_1();

};

实现:

#include "stdafx.h"
#include "ONE_1.h"
#include<time.h>
//
// Construction/Destruction
//

ONE_1::ONE_1()
{ //获取本地时间
time_t now;
time(&now);
tm*t = localtime(&now);
second = t->tm_sec;
minute = t->tm_min;
month = t->tm_mon+1;
year = t->tm_year+1900;
day = t->tm_mday;
hour = t->tm_hour;
}

ONE_1::~ONE_1()
{

}

主函数:

#include "stdafx.h"
#include<iostream.h>
#include"ONE_1.h"

int main(int argc, char* argv[])
{
ONE_1 A;
cout<<"现在是北京时间:"<<A.year<<"年"<<A.month<<"月"<<A.day<<"日 "<<A.hour<<":"<<A.minute<<":"<<A.second<<endl;

return 0 ;
}


标签:now,int,time,year,C++,tm,Time,编写,include
From: https://blog.51cto.com/u_13796931/5868969

相关文章

  • 记一次goby-poc的编写
    记一次goby-poc的编写......
  • C++ referemce and dereference
    //对reference&和dereference*的进一步理解//#include"iostream"intmain(){inta=9;//等号左边&为引用,取alias举个例子//int&a=b;b=......
  • c++ 调用 python 数据类型对照表
    ParsingargumentsandbuildingvaluesThesefunctionsareusefulwhencreatingyourownextensionsfunctionsandmethods.Additionalinformationandexamplesa......
  • C++不知算法系列之集结常规算法思想
    1.前言数据结构和算法是程序的2大基础结构,如果说数据是程序的汽油,算法则就是程序的发动机。什么是数据结构?指数据之间的逻辑关系以及在计算机中的存储方式,数据的存储......
  • c++ 调用 python 备忘
    PyBytesObject值的获取:PyObject*pFuncSetCredentialResult=PyObject_CallObject(pFuncSetCredential,pFuncSetCredentialArgs);PyBytesObject*pBytes......
  • onnxruntime 部署时input注意
     input_feed中的feats是转换成onnx时的名字,其可通过https://netron.app/ 查看onnx模型结构得到。feats2=feats2.unsqueeze(0).numpy()embeddings2=session.run(......
  • 【c&c++】C语言 结构体 - 字节对齐 使用预处理命令 #pragma 对齐
    在C语言中每个数据类型都有他的对齐方式例如char是一个一节对齐,int是四个字节对齐,float是八个字节对齐,short是两个字节对齐由于对齐方式的特性就会拥有相同成员的结......
  • [C++]-日志记录库SPDLog简介[通俗易懂]
    文章目录spdlog库日志记录槽sink日志记录器logger输出格式pattern对齐方式截断字符串格式化fmtFormatSpecificationspdlog使用异常处理logger基......
  • 【c&c++】二级指针的使用
    有时候,我们需要在函数体的内部申请内存空间并初始化,然后将内部申请的存储空间交付给外部指针来引用,这时候,我们可以使用二级指针作为申请空间的函数的参数来实现。main.c......
  • Pyomo基础学习笔记:建模组成要素的编写方法
    1、Pyomo简介pyomo文档【数学建模】优化模型建模语言Pyomo入门教程-知乎(zhihu.com)Pyomo是基于Python的开源软件包,主要功能是建立数学规划模型,包括线性规划,二......