首页 > 其他分享 >time_t now=time(NULL); std::cout<<ctime(&another_time);tm* ltm = localtime(&now);

time_t now=time(NULL); std::cout<<ctime(&another_time);tm* ltm = localtime(&now);

时间:2023-04-18 22:27:10浏览次数:37  
标签:std include NULL tm time now

#include <iostream>
#include <iomanip>
#include <ctime>
#include<windows.h>
int main() {
    time_t now = time(NULL);
    tm* ltm = localtime(&now);
    std::cout<<ctime(&now);
    std::cout << "Year: " << 1900 + ltm->tm_year << std::endl;
    std::cout << "Month: " << 1 + ltm->tm_mon << std::endl;
    std::cout << "Day: " << ltm->tm_mday << std::endl;
    std::cout << "Time: " << std::setw(2) << std::setfill('0') << ltm->tm_hour << ":";
    std::cout << std::setw(2) << std::setfill('0') << ltm->tm_min << ":";
    std::cout << std::setw(2) << std::setfill('0') << ltm->tm_sec << std::endl;
    Sleep(1220);
    time_t another_time=time(0);
    std::cout<<ctime(&another_time);
    double gap=difftime(another_time,now);
    std::cout<<"gap"<<gap<<"s"<<std::endl;
    return 0;
}

#ifndef _TM_DEFINED
#define _TM_DEFINED
  struct tm {
    int tm_sec;
    int tm_min;
    int tm_hour;
    int tm_mday;
    int tm_mon;
    int tm_year;
    int tm_wday;
    int tm_yday;
    int tm_isdst;
  };
#endif

标签:std,include,NULL,tm,time,now
From: https://www.cnblogs.com/LogicHan/p/17224521.html

相关文章

  • Python小练习:解决strftime()中国时区乱码问题
    Python小练习:解决strftime()中国时区乱码问题作者:凯鲁嘎吉-博客园 http://www.cnblogs.com/kailugaji/1.mytest.py1#-*-coding:utf-8-*-2#Author:凯鲁嘎吉CoralGajic3#https://www.cnblogs.com/kailugaji/4#Python小练习:解决strftime()中国时区乱码问......
  • 浏览器报错net::err_connection_timed_out 怎么解决
    误代码“err_connection_timed_out”的解决方案2017-04-2011:02曾经试过用浏览器访问一个或几个特定网站,出现“err_connection_timed_out”错误,而其他网站加载良好没有任何问题或错误。上网查过发现这是一个常见的互联网错误。发生此DNS错误是因为访问或浏览该网站时,Internet......
  • [FASTDDS]01-FastDDS简介
    01-FastDDS简介本节介绍DDS和RTPS的概念。本文章来源于fastdds官网中的WhatisDDS和WhatisRTPS章节1.1什么是DDSDataDisrubutionService(DDS)——数据分发服务——是一个用来进行分布式软件应用通信的协议。它描述了数据提供者和数据消费者之间的通信API以及通信语......
  • Clouds remind me that magical things in life can come out of nowhere
    Cloudscanalsotransportmeawayfromthedullerpartsoflife,awayfromboringsituationsandawayfromdaytodaystressesandworries.Theygetmeoutofmyheadandintoadreamscape,amagicallookinglandscapethatfloatsabovemewhereIcanimag......
  • 慎用std::move
    编译arm版本成功,空跑正常,跑业务崩溃在了如下函数:deliverPacket_internal_(std::move(video_packet),false,video_packet->big)x86机器运行正常. 怀疑点: 1、依赖库问题?所有的lib都copy到了运行环境,大概率不是.2、libc问题?编译环境和运行环境libc版本相同...3......
  • HttpRuntime.Cache[key] as List<string>竟然会引用转值改变Cache的值
    HttpRuntime.Cache[key]asList<string>竟然会引用转值改变Cache的值此时HttpRuntime.Cache[key]的值会发生改变 ......
  • fastdds学习之4——RTPS层
    FastDDS的较低层RTPS层是RTPS标准协议的实现。与DDS层相比,该层提供了对通信协议内部的控制,因此高级用户对库的功能有更精细的控制。1、与DDS层的关系此层的元素与来自DDS层的元素进行一对一的映射,并添加了一些内容。此对应关系如下表所示:DDSLayerRTPSLayerDomainR......
  • pom.xml报"Unknown"错误的解决
    经分析,这是maven-jar-plugin3.1.2引入的Bug,见https://bugs.eclipse.org/bugs/show_bug.cgi?id=547340。只需pom.xml追加<maven-jar-plugin.version>3.1.1</maven-jar-plugin.version>,然后mavenupdate,重新打开pom.xml就没有红叉了。<properties><java.version>1.8......
  • Again Prime? No Time. UVA - 10780
    给定m,n,求最大的k使得m^k∣n! 分解质因数   #include<iostream>#include<cstring>#include<sstream>usingnamespacestd;constintN=1e4+20;constintinf=1e9;intn,m,a[N],b[N];intprime[N],tot,vis[N];voidinit(inttop){ for(......
  • 【sip】ptime在SIP中的应用
    主叫在发送的INVITE请求中的SDP携带ptime属性,表示主叫方媒体的打包时长是ptime携带的数值。服务器收到该请求消息后回复200OK中的SDP携带ptime属性,表示服务器端支持该媒体的打包时长是ptime携带的数值。主叫方根据200OK中SDP携带ptime属性进行协商最终发送媒体打包时长,即ptime数......