UNIX & GNU/Linux - System calls - Using time()

It is sometimes useful to display the current date in your terminal.
For that the time() system call function is the best one.
Let's see an example within this tiny tutorial of C programming language:

// main.c
#include <time.h>
#include <stdio.h>

int main () {
time_t myTime;

printf("The time is: %s", ctime(&myTime));
return 0;

Compiling and executing.
And the result is:

$ The time is: Wed Feb 22 14:36:43 2012

All simply! laugh

Add new comment

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Refresh Type the characters you see in this picture. Type the characters you see in the picture; if you can't read them, submit the form and a new image will be generated. Not case sensitive.  Switch to audio verification.