Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

How to make a code, of which a bot will keep track of the date?

0 votes
asked Nov 25, 2020 by Superman365 (560 points)
Can we make a bot tell us the date?

Can it go on forever?

It should go like:




I am sure this is possible!

2 Answers

+1 vote
answered Nov 25, 2020 by Peter Minarik (89,230 points)
selected Nov 25, 2020 by Superman365
Best answer

If you want to print the date in a C program, have a look at this.

So the code would be something, like this:

#include <stdio.h>
#include <time.h>

int main()
    time_t t = time(NULL);
    struct tm dt = *localtime(&t);
    printf("now: %d-%02d-%02d %02d:%02d:%02d\n", dt.tm_year + 1900, dt.tm_mon + 1, dt.tm_mday, dt.tm_hour, dt.tm_min, dt.tm_sec);
commented Nov 25, 2020 by Superman365 (560 points)
Thanks for this answer, it was good! Can you answer this Q?
Q: How to make a timer in C Programming?
I have put the q so you don't need to comment back
+1 vote
answered Nov 25, 2020 by Peter Minarik (89,230 points)
If you are not actually after the date, but rather you would like to measure the elapsed time (for the quiz you were asking before), then you'll need a different solution.

Let me know if you need help with that.
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.