CString日期如何轉為CTime

2021-04-12 23:14:11 字數 1038 閱讀 9862

假設該   cstring   中的結構為   "%04d年%02d月%02d日",則  

cstring   timestr   =   "2023年04月05日";  

int   year,month,day;  

byte   tt[5];  

//get   year  

memset(tt,   0,   sizeof(tt));  

tt[0]   =   timestr[0];  

tt[1]   =   timestr[1];  

tt[2]   =   timestr[2];  

tt[3]   =   timestr[3];  

year=   atoi((char   *)tt);  

//get   month  

memset(tt,   0,   sizeof(tt));  

tt[0]   =   timestr[6];  

tt[1]   =   timestr[7];  

month   =   atoi((char   *)tt);  

//get   day  

memset(tt,   0,   sizeof(tt));  

tt[0]   =   timestr[10];  

tt[1]   =   timestr[11];  

ctime   time(year,month,day,0,0,0); 

或者cstring   s("2001-8-29   19:06:23");  

int   nyear,   nmonth,   ndate,   nhour,   nmin,   nsec;  

sscanf(s,   "%d-%d-%d   %d:%d:%d",   &nyear,   &nmonth,   &ndate,   &nhour,   &nmin,   &nsec);  

ctime   t(nyear,   nmonth,   ndate,   nhour,   nmin,   nsec);

CString轉為string遇到的問題

今天寫程式遇到在mfc中獲取控制項上的字元時,定義了乙個cstring型別的變數來存放。然後需要將cstring型別轉為string型別,用於其他函式的使用 出現乙個問題,導致我晚上整整花了四十幾分鐘,想死的心都有了。由於對個中字元型別不是很了解,包括c style的字串,c 中模板basic st...

怎樣把CString型別轉為char陣列

方法一 char p cstring str hello p str.getbuffer str.getlength str.releasebuffer 方法二 cstring str hello char ch 20 memcpy ch,str,str.getlength 方法三 char ch ...

php字串轉為日期格式,日期格式轉為字串

strtotime 函式將任何字串的日期時間描述解析為 unix 時間戳 自 january 1 1970 00 00 00 gmt 起的秒數 列印當前時間 php eol 換行符,相容不同系統 將指定日期轉成時間戳,例如 20190813121721 echo strtotime 20190813...