Skip to content

Instantly share code, notes, and snippets.

@fernandoc1
Created November 21, 2019 16:31
Show Gist options
  • Select an option

  • Save fernandoc1/95c4ef81486199613b2b575991fccc39 to your computer and use it in GitHub Desktop.

Select an option

Save fernandoc1/95c4ef81486199613b2b575991fccc39 to your computer and use it in GitHub Desktop.
This code prints the local time in Linux with a C program.
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <stdint.h>
int main()
{
time_t currentTime = time(NULL);
struct tm* localTime = localtime(&currentTime);
char dateStr[100];
sprintf(dateStr, "%s/%04d_%02d_%02d_%02d_%02d_%02d.h264",
"Date is: ",
localTime->tm_year + 1900,
localTime->tm_mon + 1,
localTime->tm_mday,
localTime->tm_hour,
localTime->tm_min,
localTime->tm_sec
);
printf("%s\n", dateStr);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment