Skip to content

Instantly share code, notes, and snippets.

@bgunebakan
Created January 6, 2015 20:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bgunebakan/ab83afae61e017388d14 to your computer and use it in GitHub Desktop.
Save bgunebakan/ab83afae61e017388d14 to your computer and use it in GitHub Desktop.
get date and time with c
/* Simple C program that connects to MySQL Database server*/
#include <stdio.h>
#include <string.h>
#include <time.h>
int main(){
time_t t = time(NULL);
struct tm tm = *localtime(&t);
char currentDate[10];
char currentTime[8];
//printf("now: %d-%d-%d %d:%d:%d\n", tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec);
sprintf(currentDate, "%02d.%02d.%04d", tm.tm_mday, tm.tm_mon+1, tm.tm_year + 1900);
sprintf(currentTime, "%02d:%02d:%02d", tm.tm_hour, tm.tm_min, tm.tm_sec);
printf("%s - %s\n",currentDate,currentTime);
// printf("%s",time());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment