參考來源1
參考來源2
#include
#include
#include
int main(void)
{
struct tm t;
char str[80];
/* sample loading of tm structure */
t.tm_sec = 1; /* Seconds */
t.tm_min = 30; /* Minutes */
t.tm_hour = 9; /* Hour */
t.tm_mday = 22; /* Day of the Month */
t.tm_mon = 11; /* Month */
t.tm_year = 56; /* Year - does not include century */
t.tm_wday = 4; /* Day of the week */
t.tm_yday = 0; /* Does not show in asctime */
t.tm_isdst = 0; /* Is Daylight SavTime; does not show in asctime */
/* converts structure to null terminated
string */
strcpy(str, asctime(&t));
printf("%s/n", str);
return 0;
}
#include
#include
#include
#include
int main()
{
char VEGATimeTxt[30], *tok, WDay[4], Mon[4], MDay[2], ClockTime[9] ,Year[5];
time_t sysTime;
struct tm * VEGATime;
memset( VEGATimeTxt, 0, sizeof(VEGATimeTxt) );
time( &sysTime );
VEGATime = localtime( &sysTime );
strcpy(VEGATimeTxt, asctime(VEGATime));
memset( WDay, 0, sizeof(WDay) );
memset( Mon, 0, sizeof(Mon) );
memset( MDay, 0, sizeof(MDay) );
memset( ClockTime, 0, sizeof(ClockTime) );
memset( Year, 0, sizeof(Year) );
tok = strtok( VEGATimeTxt, " " );
strcpy(WDay, tok);
tok = strtok( NULL, " " );
strcpy(Mon, tok);
tok = strtok( NULL, " " );
strcpy(MDay, tok);
tok = strtok( NULL, " " );
strcpy(ClockTime, tok);
tok = strtok( NULL, "\n" );
strcpy(Year, tok);
printf("WDay\tMon\tMDay\tClockTime\tYear\n");
printf("==== ==== ==== ========= ====\n");
printf("%s\t%s\t%s\t%s\t%s\n", WDay, Mon, MDay, ClockTime, Year);
return 0;
}
1 則留言:
thanks on the side of this nice tips 147896325
張貼留言