PDA

View Full Version : get build time and Date



mouni
29th April 2015, 09:33
Hi friends..

I am compiling application i want to display compile at which time and date....
help me to solve ...
can any body send example code ...

ChrisW67
29th April 2015, 09:44
1. Look at clock
2. Type time into source code that "display compile time"
3. Compile
4. Profit

You provide us with no useful information that might lead to a better answer.

mouni
29th April 2015, 09:56
while running the program i want to display in our widget at which time and date is compiling ....

wysota
29th April 2015, 09:57
https://gcc.gnu.org/onlinedocs/cpp/Standard-Predefined-Macros.html

mouni
29th April 2015, 10:26
I required in qt

wysota
29th April 2015, 11:20
I required in qt

11148

So you are not using a c++ compiler?

mouni
29th April 2015, 12:59
i am using c++ compiler

wysota
29th April 2015, 13:13
i am using c++ compiler

So macros defined in C++ standard will work for you.

mouni
30th April 2015, 07:48
when i compiled program exe file created.
in that example i added a dialog box in that i am showing version and time.... when it complied ...
after that 4 hours i run excutable it is showing current time it should show when i compiled program that time should be replied...
the excutable is in release mode....

wysota
30th April 2015, 09:45
Did you use __DATE__ and __TIME__ macros as I advised?

Radek
30th April 2015, 09:47
It depends on the operating system (windows in your case) and the compiler. I do not know any standard function which would provide the build time. __DATE__ and __TIME__ are useless because they provide the current date and time.

In Linux (not in windows) I would try the "backward apostrophes" ability of bash. Define a macro COMPTIME on the command line of the compiler:


-D COMPTIME=`date +"\"%F\""`


The thing between ` ` is a shell command displaying date and time. Because of ` ` the output (the date and time) will replace the command in ` ` on the command line. This way, the COMPTIME will be set to the time of compilation. The code can use COMPTIME for outputting the build time.

If you can do something similar in windows, try it.

wysota
30th April 2015, 09:56
It depends on the operating system (windows in your case) and the compiler. I do not know any standard function which would provide the build time. __DATE__ and __TIME__ are useless because they provide the current date and time.

__DATE__ and __TIME__ return date and time when the preprocessor was ran, so it's not current time but rather the time when the file is compiled.


#include <QtDebug>

int main() {
qDebug() << __DATE__ << __TIME__;
return 0;
}

wysota@localhost:/tmp/b$ ./b
Apr 30 2015 10:55:37
wysota@localhost:/tmp/b$ ./b
Apr 30 2015 10:55:37
wysota@localhost:/tmp/b$ ./b
Apr 30 2015 10:55:37
wysota@localhost:/tmp/b$ ./b
Apr 30 2015 10:55:37
wysota@localhost:/tmp/b$ LC_ALL=C date
Thu Apr 30 10:56:46 CEST 2015
wysota@localhost:/tmp/b$ ./b
Apr 30 2015 10:55:37

mouni
30th April 2015, 10:29
working fine but it is showing in 24 hour format...it should show in 12 hour format ...can tell me how to set...

wysota
30th April 2015, 10:42
working fine but it is showing in 24 hour format...it should show in 12 hour format ...can tell me how to set...

I told you in the other thread.

d_stranz
30th April 2015, 16:07
I told you in the other thread.

Your answer there was unsatisfactory, that's why he asked again. My answer in the other thread will probably also turn out to be unsatisfactory.

jefftee
1st May 2015, 03:22
Your answer there was unsatisfactory, that's why he asked again. My answer in the other thread will probably also turn out to be unsatisfactory.
Perhaps a fourth thread is needed for both of you to re-post your answers so that we have everything in one thread??? ha! :)