#include "windows.h"
#include<string>
#include<time.h>
using namespace std;
void main()
{
char str[] ="13:23:56"; //时间
const char * split = ":";//分隔符
char * p;
char *ps[3];
p = strtok (str,split);
while(p!=NULL) {
static int i=0;
ps[i]=p;
//printf ("%s\n",p);
i++;
p = strtok(NULL,split);
}
for(int j=0;j<3;j++)
{
printf("%s\n",ps[j]);
}
//转换出时间
time_t mytime;
struct tm *now;
time( &mytime);
now = localtime( &mytime);
now->tm_min =atoi(ps[0]);
now->tm_hour =atoi(ps[1]);
//now->ti_hund =0; // 其实我也不知道这个成员是干啥的
now->tm_sec =atoi(ps[2]);
//settime(&mytime);
printf("........................\n");
printf("%2u%2u%2u",now->tm_hour,now->tm_min,now->tm_sec+5);
getchar();
}
、
#include<iostream>
#include "windows.h"
#include<string>
#include<time.h>
#include<atltime.h>
using namespace std;
void main()
{
////CTime 转CString
//CTime currTime;
//CString str;
// currTime=GetCurrentTime();
//str=currTime.Format("%H:%M:%S");
//wcout<<str.GetString()<<endl;
//CTimeSpan spanTime;
//spanTime=20;
//currTime+=spanTime;
//str=currTime.Format("%H:%M:%S");
//wcout<<str.GetString()<<endl;
//getchar();
//CString 转CTime
CString timestr = "2000年04月05日";
int a,b,c ;
sscanf(timestr.GetBuffer(timestr.GetLength()),"%d年%d月%d日",&a,&b,&c);
CTime time(0,0,0,a,b,c);
CString str;
str=time.Format("%H:%M:%S");
wcout<<str.GetString()<<endl;
getchar();
/*CString sss("23:13:23");
int a,b,c;
sscanf(sss.GetBuffer(sss.GetLength()),"%d:%d:%d",&a,&b,&c);
CTime timess(0,0,0,a,b,c);
str=timess.Format("%H:%M:%S");
wcout<<str.GetString()<<endl;*/
} char szFileName[256]={0};
time_t t = time(0);
char szTimeNow[64];
strftime( szTimeNow, sizeof(szTimeNow), "%Y%m%d%H%M%S",localtime(&t) );
sprintf(szFileName,"userlabel_%s.txt",szTimeNow);
printf("%s",szFileName);