Is it possible to insert the build time into an ap

2020-03-26 08:36发布

问题:

A game has this:

I'm curious to whether this was the actual build time, and sure enough, the 'File Last Modified' date of Crysis.exe (the program) is 03/31/2009, 01:40.

Sure, the developer could easily have manually inputted that value, and built the application in under a minute, but I'm curious to whether it is actually possible to input the current date/time (to the nearest second) when the application is actually building.

This would have many advantages, including easy identification of different builds of the application.

Is this possible?

回答1:

Yes the time of built is provided by the __TIME__ macro. In your example they also use __DATE__ macro which provides the date.

LIVE DEMO



回答2:

Yes. Several approaches come to mind:

  1. Use C's __DATE__ and __TIME__ macros. They're part of the standard, however, they take the time the particular file was last built. So that means if you e.g. put the build date in your app's about screen, then the date will only be updated when you either do a complete clean build, or you change the about screen source file. To fix this, you could add a script to your build process that e.g. calls

    touch AboutScreen.cpp
    

    To forcibly trigger a rebuild.

  2. Write a shell script that you run before each build that generates a header file like

    #define BUILD_DATE  "2014-07-03 20:15"
    

    and run that script before each build. Since the file is generated new each time, your build process should notice it has changed and automatically trigger a new build of the about screen or whatever shows your build date/time.