高手来帮忙解决下时间问题!!!

时间:2008-06-20 14:45:48   来源:论坛整理  作者:  编辑:chinaitzhe
现在这个输入出的时间是2008年5月20日 11:1:1秒,,假如本地时间..我想要的是11:01:01秒..格式这应该怎么样处理??试了好多..没试出来..
#include"stdafx.h"
#include <iostream>
#include <ctime>
using namespace std;
int main(void)

{

struct tm *times;
time_t t;
t = time(0);
times = localtime(&t);
int year,month,day;
year = (times->tm_year 1900);
month = times->tm_mon;
day = times->tm_mday;
cout < <year < <"年";
cout < < month < <"月";
cout < <day < <"日" < <endl;
cout < < times->tm_hour < <":";
cout < < times->tm_min < <":";
cout < < times->tm_sec < <endl;


// system("time");
return 0;

}
网友回复:SYSTEMTIME t;
GetLocalTime(&t);
sprintf(tmpbuf,"d-d-d-d-d-d-d",
t.wYear,t.wMonth,t.wDay,t.wHour,t.wMinute,t.wSecond,t.wMilliseconds);
网友回复:why no have answer??
网友回复:string s1="";
string s2="";
if(tm_min <10) s1="0";
if(tm_sec <10) s2="0";
cout < < times->tm_hour < <":" < <s1;
cout < < times->tm_min < <":" < <s2;
cout < < times->tm_sec < <endl;
网友回复:就用1楼的就可以啦
网友回复:
引用 1 楼 bubu8633 的回复:
SYSTEMTIME t;
GetLocalTime(&t);
sprintf(tmpbuf,"d-d-d-d-d-d-d",
t.wYear,t.wMonth,t.wDay,t.wHour,t.wMinute,t.wSecond,t.wMilliseconds);

网友回复:那句放哪啊..我这里似乎用不了GetLocalTime(&t)
这个..要不就用CTime了..
是VC6.0 WIN 32
一楼那个是不是MFC里可以用的?
网友回复:
C/C code





Code highlighting produced by Actipro CodeHighlighter (freeware)

http://www.CodeHighlighter.com/





#include <iostream> 

#include <ctime> 

#include <iomanip>

using namespace std; 

int main(void) 



{ 



    struct tm *times;      

    time_t t;                    

    t = time(0);                

    times = localtime(&t);      

int year,month,day; 

year = (times->tm_year 1900); 

month = times->tm_mon; 

day = times->tm_mday; 

    cout <<year <<"年"; 

    cout << month 1 <<"月"; 

    cout <<day <<"日" <<endl;  

    cout <<setw(2)<<setfill('0')<< times->tm_hour <<":"; 

    cout << setw(2)<<setfill('0')<< times->tm_min <<":"; 

    cout << setw(2)<<setfill('0')<< times->tm_sec <<endl; 

  



system("time"); 

system("pause");

    return 0; 



}






网友回复:tengye19840704(滕滕) 很好问啊,但是怎么老是忘记结贴呢?

学习是一种美德,假如能够记得结贴更是一种美德. ^_^

网友回复:是是....不好意思 ...这就结
网友回复:回七楼,高人..方法真简单...可否告知..为什么?
网友回复:回七楼.有总是.那假如是双数.也在前面加一个0啊...
网友回复:不会,因为setw(2)限制了输出了长度, 只有是一位时才会填充0
关键字:高手,帮忙,解决,时间问题,

相关文章

文章评论

共有 0 位网友发表了评论 此处只显示部分留言 点击查看完整评论页面