VC 6.0下编写的的控制台程序(就是只有黑底白字窗口的那个)。有什么自带函数能载入系统当前时间吗?

VC6.0下编写的的控制台程序(就是只有黑底白字窗口的那个)。有什么自带函数能载入系统当前时间吗?... VC 6.0下编写的的控制台程序(就是只有黑底白字窗口的那个)。有什么自带函数能载入系统当前时间吗? 展开
 我来答
江湖三脚猫Django
2012-03-03 · TA获得超过3495个赞
知道大有可为答主
回答量:3333
采纳率:100%
帮助的人:3125万
展开全部
是要打印时间?
system("time");
如果是要在程序中获取的话,可以类似这样:
typedef union
{
struct
{
int16 year;
int8 month;
int8 mday;
int8 hour;
int8 minute;
int8 second;
int8 wday;
};
uint64 uint64val;
} OSTime;

OSTime OSTimeCurTime()
{
OSTime t = {0};
time_t ct = time(NULL);
struct tm ctm;

memcpy(&ctm, localtime(&ct), sizeof(ctm));
t.year = ctm.tm_year + 1900;
t.month = ctm.tm_mon + 1;
t.mday = ctm.tm_mday;
t.hour = ctm.tm_hour;
t.minute = ctm.tm_min;
t.second = ctm.tm_sec;
t.wday = ctm.tm_wday;

return t;
}
追问
就是把系统时间的年月日分别存入变量year,month,day中。您给的代码有点复杂了。您能否帮忙把楼下的代码改成把系统时间的年月日分别存入变量year,month,day的形式,谢谢
追答
#include 
#include
#include

void main()
{
int year,month,day;
int hour,minute,second;
time_t ct = time(NULL);
struct tm ctm;

memcpy(&ctm, localtime(&ct), sizeof(ctm));
year = ctm.tm_year + 1900;
month = ctm.tm_mon + 1;
day = ctm.tm_mday;
hour = ctm.tm_hour;
minute = ctm.tm_min;
second = ctm.tm_sec;

printf("当前时间:%4d年%2d月%2d日 %2d:%2d:%2d\n",year,month,day,hour,minute,second);
}
百度网友a9aac05dc
2012-03-03 · TA获得超过139个赞
知道小有建树答主
回答量:195
采纳率:0%
帮助的人:133万
展开全部
void GetSystemTime(
LPSYSTEMTIME lpSystemTime
);
Parameters

lpSystemTime
[out] Pointer to a SYSTEMTIME structure to receive the current system date and time.

Requirements

OS Versions: Windows CE 1.0 and later.
Header: Winbase.h.
Link Library: Coredll.lib.

void GetLocalTime(
LPSYSTEMTIME lpSystemTime
);
Parameters

lpSystemTime
[out] Pointer to a SYSTEMTIME structure to receive the current local date and time.

Requirements

OS Versions: Windows CE 1.0 and later.
Header: Winbase.h.
Link Library: Coredll.lib.
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
匿名用户
2012-03-03
展开全部
//下面的程序在VC6上验证ok,你试试:

#include<stdio.h>
#include<time.h>

int main()
{
time_t nowtime;
nowtime=time(NULL);
struct tm *local;
local=NULL;
local=localtime(&nowtime);
char *buffer=new char[12];
strftime(buffer,128,"%c",local);
printf("%s\n",buffer);

return 0;
}
追问
您好,请问。如果我只要年月日。并分别存到变量year,month,day中。这段代码该如何改?谢谢
追答
#include
#include
#include

int main()
{
time_t ct = time(NULL);
struct tm ctm;
int year,month,day;

memcpy(&ctm, localtime(&ct), sizeof(ctm));
year = ctm.tm_year + 1900;
month = ctm.tm_mon + 1;
day = ctm.tm_mday;

printf("year: %d,month: %d,day: %d\n",year,month,day);

return 0;
}
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(1)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式