1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
|
#include <stdio.h> // Needed for printf()
#include <time.h> // Needed for time data structures and functions
// Adjust for Daylight savings as needed
// Sunday, March 31 & Sunday, October 27 2013
#define PST (-8)
#define MST (-7)
#define CST (-6)
#define EST (-5)
#define UTC (0)
#define BST (+1)
#define CCT (+8)
int leap_year();
void TimeDump()
{
time_t timer; // Define the timer
struct tm *tblock; // Define a structure for time block
// Get time of day
timer = time(NULL);
// Converts date/time to a structure
tblock = localtime(&timer);
// Output ASCII data/time
printf("Local time is: %s", asctime(tblock));
// Output members of tm structure
printf("DST = %d \n", tblock->tm_isdst);
printf("Julian date = %d \n", tblock->tm_yday);
printf("Week day = %d \n", tblock->tm_wday);
printf("Year = %d \n", tblock->tm_year +1900); // based on 1900
printf("Month = %d \n", tblock->tm_mon +1); //month (0 to 11)
printf("Month day = %d \n", tblock->tm_mday); // Starts Monday
printf("Hour = %d \n", tblock->tm_hour);
printf("Minutes = %d \n", tblock->tm_min);
printf("Seconds = %d \n", tblock->tm_sec);
}
// Show Time Zones
int TimeZone ()
{
time_t rawtime;
struct tm * ptm;
time ( &rawtime );
ptm = gmtime ( &rawtime );
printf ("\n");
printf ("Location UTC \t : Time\n");
printf ("Pacific Time (UTC-7)\t : %2d:%02d\n", (ptm->tm_hour+PST)%24, ptm->tm_min);
printf ("Mountain Time (UTC-6)\t : %2d:%02d\n", (ptm->tm_hour+MST)%24, ptm->tm_min);
printf ("Central Time (UTC-5)\t : %2d:%02d\n", (ptm->tm_hour+CST)%24, ptm->tm_min);
printf ("Eastern Time (UTC-4)\t : %2d:%02d\n", (ptm->tm_hour+EST)%24, ptm->tm_min);
printf ("\n");
printf ("Universal Time (UTC0) \t : %2d:%02d\n", (ptm->tm_hour+UTC)%24, ptm->tm_min);
printf ("\n");
printf ("London England (UTC+0)\t : %2d:%02d\n", (ptm->tm_hour+BST)%24, ptm->tm_min);
printf ("Beijing China (UTC+8)\t : %2d:%02d\n", (ptm->tm_hour+CCT)%24, ptm->tm_min);
}
int main(void)
{
TimeDump();
TimeZone ();
return 0;
}
|