获取系统当前时间(日历时)

//Linux & C++11

#include <chrono>
#include <ctime>

using namespace std;

string getCurrentSystemTime()
{
    std::time_t secSinceEpoch = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now());    //Seconds since the Epoch
    struct tm* calendarTime = localtime(&secSinceEpoch);    //转换成本地日历时间
    char usrdefFormat[50] = { 0 };    //自定义格式存储位置
    strftime(usrdefFormat, 50, "%Y%m%d%H%M%S", calendarTime);    //格式:20191101135525
    return string(usrdefFormat);
}

获取从纪元到现在经历的毫秒数

//Linux & C++11

#include <chrono>

using namespace std::chrono;

uint64_t getMillSecSinchEpoch()
{
    system_clock::time_point currentTime = system_clock::now();    //当前时间
    system_clock::duration timeSinceEpoch = currentTime.time_since_epoch();    //从 Epoch 到现的纳秒数
    uint64_t millSecSinchEpoch = duration_cast<milliseconds>(timeSinceEpoch).count();    //转换为毫秒
    return millSecSinchEpoch;
}

参考资料:


未完 ......

点击访问原文(进入后根据右侧标签,快速定位到本文)

C++ 获取系统当前时间(日历时)的更多相关文章

  1. 使用js时,如何获取系统当前时间并且得到格式为"yyyy年MM月"的日期

    1.使用js时,如何获取系统当前时间并且得到格式为"yyyy年MM月"的日期: 1 var newdate = new Date(); 2 var nowyear = newdat ...

  2. Unity3D获取系统当前时间,并格式化显示

    Unity 获取系统当前时间,并格式化显示.通过“System.DateTime”获取系统当前的时间,然后通过格式化把获得的时间格式化显示出来,具体如下: 1.打开Unity,新建一个空工程,Unit ...

  3. android service 样例(电话录音和获取系统当前时间)

    关于android service 的具体解释请參考: android四大组件--android service具体解释.以下将用两个实例具体呈现Android Service的两种实现. 一个是st ...

  4. C/C++获取系统当前时间

    C/C++获取系统当前时间   C库中与系统时间相关的函数定义在<time.h>头文件中, C++定义在<ctime>头文件中. 一.time(time_t*)函数 函数定义如 ...

  5. Java基础 - Date的相关使用(获取系统当前时间)

    前言: 在日常Java开发中,常常会使用到Date的相关操作,如:获取当前系统时间.获取当前时间戳.时间戳按指定格式转换成时间等.以前用到的时候,大部分是去网上找,但事后又很快忘记.现为方便自己今后查 ...

  6. js 获取系统当前时间,判断时间大小

    1.获取系统当前时间 getNowTime(tempminit) { if (!tempminit) { tempminit = 0; } var date = new Date(); date.se ...

  7. java获取系统指定时间年月日

    java获取系统指定时间年月日 private String setDateTime(String falg) { Calendar c = Calendar.getInstance(); c.set ...

  8. Oracle,MySQL,sqlserver三大数据库如何获取系统当前时间

    Oracle中如何获取系统当前时间:用SYSDATE() MySQL中获取系统当前时间主要有以下几点: (1)now()函数以('YYYY-MM-dd HH:mm:SS')返回当前的日期时间,可以直接 ...

  9. java 获取系统当前时间并格式化

      java 获取系统当前时间并格式化 CreateTime--2018年5月9日11:41:00 Author:Marydon 实现方式有三种 updateTime--2018年7月23日09点32 ...

随机推荐

  1. Spring|@Autowired与new的区别

    前两天写代码的时候遇到一个问题,通过new出来的对象,自动注入的属性总是报空指针的错误.到网上查了资料,才发现问题所在,同时也加深了自己对于容器IOC的理解.现在把这个问题记录一下,仅供大家参考. [ ...

  2. Cesium 禁止相机进入地底下[转]

    原文:https://blog.csdn.net/thor027/article/details/82455649 viewer.clock.onTick.addEventListener(funct ...

  3. Enhancer | 增强子 专题

    要做就做深做精! Everything needs good justification. The interpretation should be biologically and statisti ...

  4. getLocation 需要在 app.json 中声明 Permission 字段

    小程序开发中,清除授权状态后,重新编译,提示:getLocation 需要在 app.json 中声明 Permission 字段 需要在 app.json 里面增加 permission 属性配置( ...

  5. pip错误 ImportError: No module named 'pip_internal'

    ubuntu16.04 - wget https://bootstrap.pypa.io/get-pip.py --no-check-certificate sudo python get-pip.p ...

  6. Python的collections之defaultdict的使用及其优势

    user_dict = {} users = ["baoshan1", "baoshan2", "baoshan3","baosh ...

  7. kinova roslaunch j2s7s300_moveit_config j2s7s300_demo.launc logs1

    luo@luo-ThinkPad-W530:~$ luo@luo-ThinkPad-W530:~$ luo@luo-ThinkPad-W530:~$ luo@luo-ThinkPad-W530:~$ ...

  8. python初级 1 内存和变量

    一.回顾: 1.什么是程序 一堆指令的集合 2.回想一下猜数游戏程序的特征: 1)需要输入(input) 2)会处理输入(process) 3)产生输出(output) 二.程序的一般特征:输入.处理 ...

  9. html中的<pre>标签

    定义和用法 pre 元素可定义预格式化的文本.被包围在 pre 元素中的文本通常会保留空格和换行符.而文本也会呈现为等宽字体. <pre> 标签的一个常见应用就是用来表示计算机的源代码. ...

  10. 带你进入异步Django+Vue的世界 - Didi打车实战

    https://www.jianshu.com/p/7e5f2090555d#!/xh?tdsourcetag=s_pcqq_aiomsg