GLYLIB
0.3.0b
|
00001 // Function written by B. Lachele Foley, 2007 00002 #include <mylib.h> 00003 //#include "../inc/mylib.h" 00004 00005 // Usage: 00006 // const char * mylocaltimestring,mytime(format) 00007 // -for example: 00008 // strcpy(mylocaltimestring,mytime("format")); 00009 // where: 00010 // format is one of: 00011 // [keyword] [example] 00012 // YYYYMMDD 20070321 00013 // YYYYMMDDhhmmss 20070321152110 00014 // pretty Wed, 21 March, 2007 00015 // longpretty 15:12:10, Wed, 21 March, 2007 00016 00017 const char * mytime(const char* timehow){ 00018 char timestring[1001],month[101],day[101]; 00019 char* tm; 00020 int DATE; 00021 struct tm TM; 00022 time_t LT; 00023 00024 // Get date 00025 LT = time(NULL); 00026 TM = *localtime(<); 00027 switch(TM.tm_mon){ 00028 case 0: strcpy(month,"January"); 00029 break; 00030 case 1: strcpy(month,"February"); 00031 break; 00032 case 2: strcpy(month,"March"); 00033 break; 00034 case 3: strcpy(month,"April"); 00035 break; 00036 case 4: strcpy(month,"May"); 00037 break; 00038 case 5: strcpy(month,"June"); 00039 break; 00040 case 6: strcpy(month,"July"); 00041 break; 00042 case 7: strcpy(month,"August"); 00043 break; 00044 case 8: strcpy(month,"September"); 00045 break; 00046 case 9: strcpy(month,"October"); 00047 break; 00048 case 10: strcpy(month,"November"); 00049 break; 00050 case 11: strcpy(month,"December"); 00051 break; 00052 default: mywhine("Error assigning month in mytime.c"); 00053 } 00054 switch(TM.tm_wday){ 00055 case 0: strcpy(day,"Monday"); 00056 break; 00057 case 1: strcpy(day,"Tuesday"); 00058 break; 00059 case 2: strcpy(day,"Wednesday"); 00060 break; 00061 case 3: strcpy(day,"Thursday"); 00062 break; 00063 case 4: strcpy(day,"Friday"); 00064 break; 00065 case 5: strcpy(day,"Saturday"); 00066 break; 00067 case 6: strcpy(day,"Sunday"); 00068 break; 00069 default: mywhine("Error assigning week day in mytime.c"); 00070 } 00071 if(strcmp(timehow,"YYYYMMDD")==0){ 00072 // YYYYMMDD 20070321 00073 DATE=19000000 + TM.tm_year*10000 + (TM.tm_mon+1)*100 + TM.tm_mday; 00074 sprintf(timestring,"%d",DATE); 00075 } 00076 if(strcmp(timehow,"YYYYMMDDhhmmss")==0){ 00077 // YYYYMMDDhhmmss 20070321152110 00078 DATE=190000 + TM.tm_year*100 + (TM.tm_mon+1); 00079 sprintf(timestring,"%d",DATE); 00080 DATE=TM.tm_mday*1000000 + 10000*TM.tm_hour + 100*TM.tm_min + TM.tm_sec; 00081 sprintf(timestring,"%s%d",timestring,DATE); 00082 } 00083 if(strcmp(timehow,"pretty")==0){ 00084 // pretty Wednesday, 21 March, 2007 00085 DATE=1900+TM.tm_year; 00086 sprintf(timestring,"%s, %d %s, %d",day,TM.tm_mday,month,DATE); 00087 } 00088 if(strcmp(timehow,"longpretty")==0){ 00089 // longpretty 15:12:10, Wednesday, 21 March, 2007 00090 DATE=1900+TM.tm_year; 00091 sprintf(timestring,"%02d:%02d:%02d, %s, %d %s, %d",TM.tm_hour,TM.tm_min,\ 00092 TM.tm_sec,day,TM.tm_mday,month,DATE); 00093 } 00094 tm = timestring; 00095 return tm; 00096 }