加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c – 编译时可以获得时间(当天)和日期吗?

发布时间:2020-12-16 03:20:20 所属栏目:百科 来源:网络整理
导读:在编译时可以通过时间和日期(BUILDTIME)知道在二进制文件(可执行文件/库)中以可移植的方式将有关创建时刻的信息纳入其中? 我们目前有一个使用sh.exe的解决方案,并且需要在Windows下安装msys,但是我想知道是否可以在没有它的情况下执行. 搜索“建立时间/日期
在编译时可以通过时间和日期(BUILDTIME)知道在二进制文件(可执行文件/库)中以可移植的方式将有关创建时刻的信息纳入其中?

我们目前有一个使用sh.exe的解决方案,并且需要在Windows下安装msys,但是我想知道是否可以在没有它的情况下执行.

搜索“建立时间/日期”,“编译时间/日期”等内容并没有产生任何相关的结果.

编辑:

当我知道__TIME__时,可能会发现这个问题以前被问过:Recording the time when you compile a source

解决方法

标准宏__DATE__和__TIME__宏完成了这项工作.

请注意,这将为您提供使用它们的文件的编译日期.不是链接日期.因此,您必须在每次构建文件时触摸文件,或在MSVC中执行预构建步骤.

The C99 standard says:

6.10.8 Predefined macro names

The following macro names shall be defined by the implementation:

  • __DATE__: The date of translation of the preprocessing translation unit: a character string literal of the form “Mmm dd
    yyyy”,where the names of the months are the same as those generated
    by the asctime function,and the first character of dd is a space
    character if the value is less than 10. If the date of translation is
    not available,an implementation-defined valid date shall be supplied.
  • __TIME__: The time of translation of the preprocessing translation unit: a character string literal of the form “hh:mm:ss” as
    in the time generated by the asctime function. If the time of
    translation is not available,an implementation-defined valid time
    shall be supplied.

我在这里复制了C99文本,但是这些宏比C99要老得多…我没有设法找到旧的C …的标准文本

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读