Last active
August 29, 2015 14:05
-
-
Save artur-kink/e90a8b7e54ca7b6cdd73 to your computer and use it in GitHub Desktop.
Get current current day time in fractional days format.
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
#include <stdio.h> | |
#include <time.h> | |
int main(int argc, char** argv){ | |
//Get current time | |
time_t now = time(0); | |
struct tm* now_tm = localtime(&now); | |
//Get midnight today | |
struct tm today; | |
today.tm_sec = 0; | |
today.tm_min = 0; | |
today.tm_hour = 0; | |
today.tm_year = now_tm->tm_year; | |
today.tm_mon = now_tm->tm_mon; | |
today.tm_mday = now_tm->tm_mday; | |
//Get seconds since midnight today. | |
double seconds = difftime(now, mktime(&today)); | |
//Get fractional time. | |
double fraction = seconds/(60*60*24); | |
printf("%f\n", fraction); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment