69,366
社区成员
发帖
与我相关
我的任务
分享
#include <stdio.h>
#include <time.h>
#include <string.h>
int main()
{
time_t result = time(NULL);
struct tm t;
memcpy(&t, localtime(&result), sizeof(struct tm));
printf("%d-%d-%d\t%d:%d:%d", t.tm_year + 1900, t.tm_mon, t.tm_mday, t.tm_hour, t.tm_min, t.tm_sec);
return 0;
}
// crt_mktime.c
/* The example takes a number of days
* as input and returns the time, the current
* date, and the specified number of days.
*/
#include <time.h>
#include <stdio.h>
int main( void )
{
struct tm when;
__time64_t now, result;
int days;
char buff[80];
time( &now );
_localtime64_s( &when, &now );
asctime_s( buff, sizeof(buff), &when );
printf( "Current time is %s\n", buff );
days = 20;
when.tm_mday = when.tm_mday + days;
if( (result = mktime( &when )) != (time_t)-1 ) {
asctime_s( buff, sizeof(buff), &when );
printf( "In %d days the time will be %s\n", days, buff );
} else
perror( "mktime failed" );
}