Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Print Date and Time In Visual Studio C++ build?

How would I print the date and time for the purposes of the build. Ie: When the console for my application starts up I want to do this:

Binary Build date: 03/03/2009 @ 10:00AM

I think this would be a super useful function for all applications to have behind the scenes for programmers, especially in a team environment.

Is there a simple way to do this using Visual Studio 2008 in C++. Thanks.

like image 786
Brock Woolf Avatar asked Mar 02 '09 16:03

Brock Woolf


People also ask

How do I insert date and time in Visual Studio?

Following commands are available: Insert DateTime (⇧+⌘+I on OS X, Ctrl+Shift+I on Windows and Linux) - Inserts current date and/or time according to configured format ( format ) at the cursor position. Insert Date - Inserts current date according to configured format ( formatDate ) at the cursor position.

How do I check compile time in Visual Studio?

User guide. Open the tool window from the top menu View -> Other Windows -> Build Timer. Start building your Visual Studio solution. Build Timer records time spent building each project and creates a timeline presented as a bar chart.

How do I get the current date in Visual Studio?

To access the current system date as a String , use the DateString property. To get or set the current system time, use the TimeOfDay property.


1 Answers

Similar to Virne's answer I created a simple header file called "BuildDate.h" with the following contents:

#define BUILD_DATE __DATE__ " " __TIME__

I touch the file using GnuWin32 touch command in my pre-build event:

touch.exe BuildDate.h

Then I include the header file in any code where I want access to the BUILD_DATE string. E.g.:

#include "BuildDate.h"
...
logger->Log("Build Date: " BUILD_DATE);
like image 58
User Avatar answered Oct 01 '22 10:10

User