VC 6.0下编写的的控制台程序(就是只有黑底白字窗口的那个)。有什么自带函数能载入系统当前时间吗?
VC6.0下编写的的控制台程序(就是只有黑底白字窗口的那个)。有什么自带函数能载入系统当前时间吗?...
VC 6.0下编写的的控制台程序(就是只有黑底白字窗口的那个)。有什么自带函数能载入系统当前时间吗?
展开
3个回答
展开全部
是要打印时间?
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;
}
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);
}
展开全部
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.
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;
}
#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;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询