C Tutorial/time.h/localtime

Материал из C\C++ эксперт
Перейти к: навигация, поиск

localtime

Item Value Header file time.h Declaration struct tm *localtime(const time_t *time); Return returns local time.


#include <time.h>
  #include <stdio.h>
  /* Print local and UTC time. */
  int main(void)
  {
    struct tm *local;
    time_t t;
    t = time(NULL);
    local = localtime(&t);
    printf("Local time and date: %s\n", asctime(local));
    local = gmtime(&t);
    printf("UTC time and date: %s\n", asctime(local));
    return 0;
  }