Code:
// time_convertor.c
// Manilia, Phillipines (15 hrs ahead of San Diego)
// Denver, CO (1 hr ahead of San Diego)
#include <string.h>
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#define MDT (-6) // Mountain Daylight Time
#define CCT (+8) // Phillipine Standard Time
#define PDT (-7) // Pacific Daylight Time
void co(void);
void ph(void);
int main(int argc, char *argv[])
{
time_t now;
struct tm *ptr;
char buf1[80];
printf("Timezone Convertor v0.01\n");
printf("FLAGS: -co or -ph\n");
time(&now);
ptr = localtime(&now);
strftime(buf1, 80, "%x - %I:%M%p", ptr);
printf("Pacific Daylight Time : |%s|\n", buf1);
char str1[] = "-co";
char str2[] = "-ph";
int result;
int result_2;
result = strcmp(argv[1], str1);
if(result == 0)
{
co();
}
result_2 = strcmp(argv[1], str2);
if(result_2 == 0)
{
ph();
}
return 0;
}
void co(void)
{
time_t now;
struct tm *ptr;
time(&now);
ptr = gmtime(&now);
printf("Denver : %2d:%02d\n", (ptr->tm_hour+MDT)%24, ptr->tm_min);
exit(1);
}
void ph(void)
{
time_t now;
struct tm *ptr;
time(&now);
ptr = gmtime(&now);
printf("Phillipines : %2d:%02d\n", (ptr->tm_hour+CCT)%24, ptr->tm_min);
exit(1);
}
I was wondering how to use strftime() formatting with these two lines
Code:
printf("Denver : %2d:%02d\n", (ptr->tm_hour+MDT)%24, ptr->tm_min);
printf("Phillipines : %2d:%02d\n", (ptr->tm_hour+CCT)%24, ptr->tm_min);
I am even confused. Does this even make sense?
Thanks.