#include
#include
#include
#include
using namespace std;
int main(int argc, char *argv[])
{
time_t tNow =time(NULL);
time_t tEnd = tNow + 1800;
//在这里修改程序
//struct tm* ptm = localtime(&tNow);
//struct tm* ptmEnd = localtime(&tEnd);
struct tm ptm = { 0 };
struct tm ptmEnd = { 0 };
localtime_r(&tNow, &ptm);
localtime_r(&tEnd, &ptmEnd);
char szTmp[50] = {0};
strftime(szTmp,50,"%H:%M:%S",&ptm);
char szEnd[50] = {0};
strftime(szEnd,50,"%H:%M:%S",&ptmEnd);
printf("%s /n",szTmp);
printf("%s /n",szEnd);
system("PAUSE");
return EXIT_SUCCESS;
}
#include
#include
char* getDateTime();
int main()
{
char* nowtime = getDateTime();
printf("%s\n", nowtime);
return 0;
}
char* getDateTime()
{
static char nowtime[20];
time_t rawtime;
struct tm* ltime;
time(&rawtime);
ltime = localtime(&rawtime);
strftime(nowtime, 20, "%Y-%m-%d %H:%M:%S", ltime);
return nowtime;
}