This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Display TIME and DATE

Could some body in this forum advise me with
a simple code on how to diplay DATE and TIME
using printf() statement. I tried cut and paste the one posted here, and it did not
even compile ... whole bunch of syntax errors !!!!


Thanks in advance,



JIMMY

Parents Reply Children
  • OR even just:

    printf( __DATE__ __TIME__ );
    since __DATE__ and __TIME__ are both string literals, and the compiler concatenates adjacent string literals, and you don't need a format string if you're just printing a string literal.

  • What I do is just have a single file - eg, timestamp.c - in the project which just defines a string containing the date & Time:

    char timestamp[] = __DATE__ __TIME__;
    (note that there's no need for sizeof - the compiler does all that automatically!)

    I set this file to 'Always Build' in the uVision Project.
    make the timestamp symbol public, and anything in your code can display the build date & time whenever it wants.

    You could even include such a variable in each of your source files, to give each one a build timestamp, if you wanted (and if you had ROM space to burn!).

  • "and you don't need a format string if you're just printing a string literal"

    Might as well dump the printf() as well and just use puts().

    Stefan