Skip to content

Instantly share code, notes, and snippets.

@tmcw
Created August 26, 2012 00:17
Show Gist options
  • Save tmcw/3472701 to your computer and use it in GitHub Desktop.
Save tmcw/3472701 to your computer and use it in GitHub Desktop.
#import "stdio.h"
#import "time.h"
#import "string.h"
// make now
int main() {
time_t now;
int hour;
char ampm[2];
struct tm * local;
time(&now);
local = localtime(&now);
if (local->tm_hour > 12) {
hour = local->tm_hour - 12;
strncpy(ampm, "pm", 2);
} else {
hour = local->tm_hour;
strncpy(ampm, "am", 2);
}
int seconds_since_midnight = (local->tm_hour * 3600) +
(local->tm_min * 60) +
(local->tm_sec);
int day_seconds = 24 * 60 * 60;
int day_percent = (seconds_since_midnight * 100) / day_seconds;
int week_percent = ((local->tm_wday * day_seconds) +
(seconds_since_midnight) * 100) / (7 * day_seconds);
int year_percent = (((local->tm_yday * day_seconds) +
seconds_since_midnight) * 100) / (365 * day_seconds);
printf("%d:%02d%s d%d%% w%d%% y%d%%\n", hour, local->tm_min, ampm,
day_percent, week_percent, year_percent);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment