Created
January 6, 2015 20:24
-
-
Save bgunebakan/ab83afae61e017388d14 to your computer and use it in GitHub Desktop.
get date and time with c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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