Get local time

    0

    0

    Giovanny Gongora

    Codiga's C Recipes

    Get local time in ISO format

    #include <stdio.h>
    #include <time.h>
    #include <sys/time.h>
    
    void getLocalTime(time_t sec){
      printf("GetDateTime3:\t");
      char timeStr[20] = {0};
      struct tm *dateTime = localtime(&sec);
      sprintf(timeStr, "%d-%02d-%02d %02d:%02d:%02d",
              dateTime->tm_year + 1900,
              dateTime->tm_mon + 1,
              dateTime->tm_mday,
              dateTime->tm_hour,
              dateTime->tm_min,
              dateTime->tm_sec);
      printf("%s\n", timeStr);
    }
    
    Codiga Logo
    Codiga Hub
    • Rulesets
    • Playground
    • Snippets
    • Cookbooks
    Legal
    • Security
    • Privacy Policy
    • Code Privacy
    • Terms of Service
    soc-2 icon

    We are SOC-2 Compliance Certified

    G2 high performer medal

    Codiga – All rights reserved 2022.