开发者社区> 问答> 正文

获取当前的时间秒出错? 400 报错

获取当前的时间秒出错? 400 报错

今天没事随便写写发现获取的时间不对,求指教;

红帽虚拟机:c++程序  

#include <iostream>
#include <time.h>
using namespace std;


class Date
{
        int year;
        int month;
        int day;
        int hour;
        int min;
        int sec;
        public:
        void showDate()
        {
                cout<<year<<"-"<<month<<"-"<<day<<" "<<sec<<":"<<min<<":"<<hour<<endl;


        }
        void getlocalTime()
        {
                time_t curtime = time(0);
                tm tim = *localtime(&curtime);
                sec = tim.tm_sec;
                min = tim.tm_min;
                sec = tim.tm_hour;
                day = tim.tm_mday;
                month = tim.tm_mon+1;
                year = tim.tm_year+1900;


        }


运行结果:

2014-11-8 11:58:0

时跟分为什么我要倒过来输出  秒运行出来不对

展开
收起
爱吃鱼的程序员 2020-05-29 17:27:30 344 0
1 条回答
写回答
取消 提交回答
  • https://developer.aliyun.com/profile/5yerqm5bn5yqg?spm=a2c6h.12873639.0.0.6eae304abcjaIB

    自己看清楚啊  这种问题也问?

     sec = tim.tm_hour;

    2020-05-29 17:27:32
    赞同 展开评论 打赏
问答分类:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
面向失败设计 立即下载
低代码开发师(初级)实战教程 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载