CTime tm;tm=CTime::GetCurrentTime();CString str; str=tm.FormatGmt("%S:%M:%H UTC , %b %d , %Y");
SORRY,我没说清楚 ,是要求“自00:00:00 UTC, January 1, 1970的秒数”来表示,如245734626523秒。
void main( void ) { time_t ltime = 245734626523; time( <ime ); printf( "The time is %s\n", ctime( <ime ) ); }ctime函数,见MSDN
你这个数也太大了,都超出了UINT能表示的范围,你从哪里算出这个数的?
time_t nSecond;::time(&nSecond); int n=(int)nSecond;
就是.只有一个dword的表示范围..
CTime curtime; curtime=CTime::GetCurrentTime(); int year=curtime.GetYear(); int month=curtime.GetMonth(); int day=curtime.GetDay(); int hour=curtime.GetHour(); int minute=curtime.GetMinute(); int second=curtime.GetSecond();
不是呀,不是呀,我是说先获取本机时间,然后用“自00:00:00 UTC, January 1, 1970的秒数”来表示出来。
time_t nSecond;::time(&nSecond);nSecond就是自00:00:00 UTC, January 1, 1970的秒数表示的本机时间
见MSDN: /* Get UNIX-style time and display as number and string. */ time( <ime ); printf( "Time in seconds since UTC 1/1/70:\t%ld\n", ltime ); printf( "UNIX time and date:\t\t\t%s", ctime( <ime ) );
CTime::GetGmtTm ();
CString str;
str.Format("%d:%d...",time.GetYear()...);
str=tm.FormatGmt("%S:%M:%H UTC , %b %d , %Y");
{
time_t ltime = 245734626523; time( <ime );
printf( "The time is %s\n", ctime( <ime ) );
}ctime函数,见MSDN
int n=(int)nSecond;
curtime=CTime::GetCurrentTime();
int year=curtime.GetYear();
int month=curtime.GetMonth();
int day=curtime.GetDay();
int hour=curtime.GetHour();
int minute=curtime.GetMinute();
int second=curtime.GetSecond();
/* Get UNIX-style time and display as number and string. */
time( <ime );
printf( "Time in seconds since UTC 1/1/70:\t%ld\n", ltime );
printf( "UNIX time and date:\t\t\t%s", ctime( <ime ) );
myself = fopen("a.txt", "a++");
fwrite(&nSecond,sizeof(int),1, myself);
fclose(myself);
return;time_t 不是LONG类型的吗?为什么写进文件是乱码?