Categories:
.NET (357)
C (330)
C++ (183)
CSS (84)
DBA (2)
General (7)
HTML (4)
Java (574)
JavaScript (106)
JSP (66)
Oracle (114)
Perl (46)
Perl (1)
PHP (1)
PL/SQL (1)
RSS (51)
Software QA (13)
SQL Server (1)
Windows (1)
XHTML (173)
Other Resources:
How can I get the current date or time of day in a C program?
How can I get the current date or time of day in a C program?
✍: Guest
Just use the time, ctime, localtime and/or strftime functions. Here is a simple example:
#include <stdio.h>
#include <time.h>
int main()
{
time_t now;
time(&now);
printf("It's %s", ctime(&now));
return 0;
}
Calls to localtime and strftime look like this:
struct tm *tmp = localtime(&now);
char fmtbuf[30];
printf("It's %d:%02d:%02d\n",
tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
strftime(fmtbuf, sizeof fmtbuf, "%A, %B %d, %Y", tmp);
printf("on %s\n", fmtbuf);
(Note that these functions take a pointer to the time_t variable, even when they will not be modifying it.
2015-08-07, 1216👍, 0💬
Popular Posts:
How To Delete All Rows a Table? - MySQL FAQs - Understanding SQL INSERT, UPDATE and DELETE Statement...
How To Use Subqueries in the FROM clause? - MySQL FAQs - SQL SELECT Statements with JOIN and Subquer...
How To Write a Minimum Atom 1.0 Feed File? - RSS FAQs - Atom Feed Introduction and File Generation I...
How Many Tags Are Defined in HTML 4.01? There are 77 tags defined in HTML 4.01: a abbr acronym addre...
How To Run a JUnit Test Class? A JUnit test class usually contains a number of test methods. You can...