Skip to content

Instantly share code, notes, and snippets.

@uahim
Last active March 23, 2022 18:56
Show Gist options
  • Select an option

  • Save uahim/442291eb58698589f63f179b3b7ff9a5 to your computer and use it in GitHub Desktop.

Select an option

Save uahim/442291eb58698589f63f179b3b7ff9a5 to your computer and use it in GitHub Desktop.
a little formatting change
// Uptime.c
// William Riley
// 4/99
// Returns the amount of time since windows was started
//
// Changes in line 11f and 43-50
#include <stdio.h>
#include <time.h>
#include <windows.h>
#include <process.h>
// ^^ process.h is required for Windoze
int main()
{
//Program variables
long w_days, w_hours, w_minutes, w_seconds;
DWORD uptime_ret;
char timebuf[128];
//Get current time
_tzset();
_strtime_s(timebuf, 128);
//Initialize time values to zero
w_days = 0;
w_hours = 0;
w_minutes = 0;
w_seconds = 0;
//Get the number of milliseconds since Windows was started
uptime_ret = GetTickCount();
//Calculate number of seconds
w_seconds = uptime_ret/1000;
//Calculate number of minutes
w_minutes = w_seconds/60;
w_seconds = w_seconds % 60;
//Calculate number of hours
w_hours = w_minutes/60;
w_minutes = w_minutes % 60;
//Calculate number of days
w_days = w_hours/24;
w_hours = w_hours % 24;
//Print the information
if (w_days == 0)
{
//Added "0" days padding
printf("00d:" "%02dh:%02dm:%02ds\n", w_hours, w_minutes, w_seconds);
} else {
//Reformatted a little
printf("%02dd:%02dh:%02dm:%02ds\n", w_days, w_hours, w_minutes, w_seconds);
}
//printf("offset %lds\n", timeinfo->tm_gmtoff);
//We're done
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment