Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get current date time of the system in seconds

Tags:

c++

How can I get current date time of the systems in seconds in C++?

I tried this one:

struct tm mytm = { 0 };
time_t result;

result = mktime(&mytm);

printf("%lld\n", (long long) result); 

but I got: -1?

like image 854
olidev Avatar asked Jan 14 '13 09:01

olidev


1 Answers

/* time example */
#include <stdio.h>
#include <time.h>

int main ()
{
  time_t seconds;

  seconds = time (NULL);
  printf ("%ld seconds since January 1, 1970", seconds);

  return 0;
}
like image 178
Asmita Avatar answered Sep 19 '22 13:09

Asmita