我想分别看看取系统当前时间的函数:getlocaltime
getdate
gettime这三个函数的输出结果有什么不同,我只要能在dos平台上运行出结果就行了,可我就是调用不对,高手帮帮我.
getdate
gettime这三个函数的输出结果有什么不同,我只要能在dos平台上运行出结果就行了,可我就是调用不对,高手帮帮我.
解决方案 »
- 能否让多个窗口同时响应鼠标消息
- 对话框OnInitDialog失败后的问题
- 高手请进:帮我解决recvfrom的问题?(如果接收的数据不定长,那怎么设置接受的长度呢)
- 编写一个简单的动态库(DLL),其中至少导出(export)一个函数。
- 一些基本问题,答完结帖!!
- 【雪山飞车】在炎热的夏天里体验在雪山上飞速驰骋的快感,感受无比刺激的游戏人生!界面美观,操作方便,不妨一玩!
- 菜鸟又遇到error了,csdn的朋友请看错误入内
- 怎么把一个cstring或int型的数转成16进制的?用cstring表示的
- 高手呀,可以说具体点么,急
- vc入不了门,给一点建议。
- 高分,在线等待,菜鸟!怎样丛.txt中读取数字,再转换为int,真的很急
- 什么是伪代码?
如何得到当前时间日期
(topgrass发表于2001-8-5 14:48:33)一、使用MFC可以用以下代码得到CTime time = CTime::GetCurrentTime(); ///构造CTime对象
int m_nYear = time.GetYear(); ///年
int m_nMonth = time.GetMonth(); ///月
int m_nDay = time.GetDay(); ///日
int m_nHour = time.GetHour(); ///小时
int m_nMinute = time.GetMinute(); ///分钟
int m_nSecond = time.GetSecond(); ///秒我们还可以用CTime::Format函数将CTime对象转换为字符串对象
例如:
CString m_strTime = time.Format("%Y-%m-%d %H:%M:%S");运行结果:m_strTime为 2001-8-1 12:11:05二、使用GetSystemTime()这个API函数得到系统时间SYSTEMTIME ti;
GetSystemTime(&ti);
////我们可以通过读取SYSTEMTIME结构体成员直接得到时间
typedef struct _SYSTEMTIME {
WORD wYear;
WORD wMonth;
WORD wDayOfWeek;
WORD wDay;
WORD wHour;
WORD wMinute;
WORD wSecond;
WORD wMilliseconds;
} SYSTEMTIME, *PSYSTEMTIME; 例如:ti.wMilliseconds;可以得到毫秒时间
WORD m_day;
GetSystemTime();
m_day=mySysTime.wDay;................
MS-DOS Date and Time
MS-DOS date and MS-DOS time are packed 16-bit values that specify the month, day, year, and time of day an MS-DOS file was last written to. MS-DOS records the date and time whenever an MS-DOS application creates or writes to a file. MS-DOS applications retrieve this date and time using MS-DOS functions. When you use the GetFileTime function to retrieve the file times for files that were created by MS-DOS, GetFileTime automatically converts MS-DOS dates and times to UTC-based times. If you encounter an MS-DOS date and time that has not been converted, you can convert it to a UTC-based time by using the DosDateTimeToFileTime function. This function copies the converted date and time to a FILETIME structure. You can convert the value back to an MS-DOS date and time by using the FileTimeToDosDateTime function.
用time吧
例#include <time.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/timeb.h>
#include <string.h>void main()
{
char tmpbuf[128], ampm[] = "AM";
time_t ltime;
struct _timeb tstruct;
struct tm *today, *gmt, xmas = { 0, 0, 12, 25, 11, 93 }; /* Set time zone from TZ environment variable. If TZ is not set,
* the operating system is queried to obtain the default value
* for the variable.
*/
_tzset(); /* Display operating system-style date and time. */
_strtime( tmpbuf );
printf( "OS time:\t\t\t\t%s\n", tmpbuf );
_strdate( tmpbuf );
printf( "OS date:\t\t\t\t%s\n", tmpbuf ); /* Get UNIX-style time and display as number and string. */
time( <ime );
printf( "Time in seconds since UTC 1/1/70:\t%ld\n", ltime );
printf( "UNIX time and date:\t\t\t%s", ctime( <ime ) ); /* Display UTC. */
gmt = gmtime( <ime );
printf( "Coordinated universal time:\t\t%s", asctime( gmt ) ); /* Convert to time structure and adjust for PM if necessary. */
today = localtime( <ime );
if( today->tm_hour > 12 )
{
strcpy( ampm, "PM" );
today->tm_hour -= 12;
}
if( today->tm_hour == 0 ) /* Adjust if midnight hour. */
today->tm_hour = 12; /* Note how pointer addition is used to skip the first 11
* characters and printf is used to trim off terminating
* characters.
*/
printf( "12-hour time:\t\t\t\t%.8s %s\n",
asctime( today ) + 11, ampm ); /* Print additional time information. */
_ftime( &tstruct );
printf( "Plus milliseconds:\t\t\t%u\n", tstruct.millitm );
printf( "Zone difference in seconds from UTC:\t%u\n",
tstruct.timezone );
printf( "Time zone name:\t\t\t\t%s\n", _tzname[0] );
printf( "Daylight savings:\t\t\t%s\n",
tstruct.dstflag ? "YES" : "NO" ); /* Make time for noon on Christmas, 1993. */
if( mktime( &xmas ) != (time_t)-1 )
printf( "Christmas\t\t\t\t%s\n", asctime( &xmas ) ); /* Use time structure to build a customized time string. */
today = localtime( <ime ); /* Use strftime to build a customized time string. */
strftime( tmpbuf, 128,
"Today is %A, day %d of %B in the year %Y.\n", today );
printf( tmpbuf );
}
//#include "stdafx.h"
#include "Windows.h"int main(int argc, char* argv[])
{
LPSYSTEMTIME lplocaltime = 0;
GetLocalTime (lplocaltime);
WORD wYear = lplocaltime->wYear ;
WORD wMonth = lplocaltime->wMonth ;
WORD wDay = lplocaltime->wDay ;
return 0;
}
GetLocalTime()获得的为本地时间
GetSystemTime()获得的为Universal Time (格林尼治)时间与我国时间有8小时差
本程序为VC6.0控制台程序