I am creating a client-server application. I want to make some notes.
The server is in C. Now I am printing messages to the terminal. So I will probably just copy this into sprintf and add a timestamp. How can I make this timestamp? It should probably include date, hours, minutes, seconds.
#include <time.h> void timestamp() { time_t ltime; /* calendar time */ ltime=time(NULL); /* get current cal time */ printf("%s",asctime( localtime(<ime) ) ); }
It just prints on my PC
Wed Mar 07 12:27:29 2012
Check out the full range of time related features. http://pubs.opengroup.org/onlinepubs/7908799/xsh/time.h.html
Please find the version of Pavan's safe answer below.
time_t ltime; struct tm result; char stime[32]; ltime = time(NULL); localtime_r(<ime, &result); asctime_r(&result, stime);
See this for more details.
Source: https://habr.com/ru/post/1400162/More articles:C # Why is Linq broken into Null if the value is not null? - c #Would you choose SWFUpload or Plupload for the file downloader? - fileGnuPGME: GPG C ++ Signature - c ++.NET Object Mapping, Object Grouping - .netApply the same autocomplete action to multiple form fields? - jqueryGetting a connection string in a C # service - c #How to get connection string from another project in LINQ to SQL? - c #Make TreeMap Comparator Valid - javaPlay Video in Java Swing - javaHow to list existing folder components using WebDAV URLs in Tridion? - tridionAll Articles