Q:

C program to get current system date and time in Linux

0

C program to get current system date and time in Linux

This program will get the current system date and time in Linux operating system using GCC or G++ compiler.

System local time can be extracted by using struct tm, and function localtime() which are declared in <time.h> header file. Following are the members of tm structure: tm.tm_mday, tm.tm_mon, tm.tm_year, tm.tm_hour, tm.tm_min, tm.tm_sec.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Print system Date and Time in Linux using C program

/*C program to get current system date and time in Linux.*/

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

int main()
{
    time_t T = time(NULL);
    struct tm tm = *localtime(&T);

    printf("System Date is: %02d/%02d/%04d\n", tm.tm_mday, tm.tm_mon + 1, tm.tm_year + 1900);
    printf("System Time is: %02d:%02d:%02d\n", tm.tm_hour, tm.tm_min, tm.tm_sec);

    return 0;
}

Output:

System Date is: 13/03/2014
System Time is: 12:40:59

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

C language important programs ( Advance Programs )

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Function Pointer example program in C programming... >>
<< gotoxy(), clrscr(), getch() and getche() functions...