C++Builder 程序员博客
6 Aug
我在一个程序里要得到系统日期.知道有相关的API函数,但不知如何在BCB中加入想用的相关函数.望高手指教.谢谢!
取本机的:Now()
取服务器SQL:select getdate() as Rtime
NOW()怎么用?谢谢
void __fastcall TForm1::Button1Click(TObject *Sender)
{
TDateTime t=Now();
ShowMessage(t);
}
GetSystemTime
The GetSystemTime function retrieves the current system date and time. The system time is expressed in Coordinated Universal Time (UTC).
VOID GetSystemTime(
LPSYSTEMTIME lpSystemTime // address of system time structure
);
Parameters
lpSystemTime
Pointer to a SYSTEMTIME structure to receive the current system date and time.
ShowMessage(DateToStr(Now()));
TDateTime t=Now();
ShowMessage(t.DateString());
ShowMessage(t.DateTimeString());
这样的函数一般都能在time.h下找得到
SYSTEMTIME time
GetLocalTime(&time);
FormatDateTime( "dddd,mmmm,d,yyyy,hh:mm AM/PM ",Now());
TDateTime t=Now();
t.DateString()); 日期
t.DateTimeString()); 时间
这个很好..
TDateTime t=Now();
t.DateString()); 日期
t.DateTimeString()); 时间
JF
TDateTime dt = Now();
AnsiString st = dt.FormatString( "YYYYY-MM-DD HH:NN:SS ");
ShowMessage(st);
TDataTime GetDate;
AnsiString thisTime = GetDate.CurrentDateTime().Format( "yyyy-mm-dd ");
哪在API中获得系统函数是什么呢? 另外SYSTEMTIME结构是用来存放时间的吗?
哪在API中获得系统函数是什么呢? 另外SYSTEMTIME结构是用来存放时间的吗?
SYSTEMTIME time
GetLocalTime(&time);
是的,查帮助!
哦 那么这么写可以么?
…
SYSTEMTIME time;
……
MessageBox(hwnd,time.wYear, "time ",NULL);
time.wYear是WORD类型的 参数是CHAR类型 那么 把WORD类型转为CHAR 然后再用MessageBox() 可以实现吗?
AnsiString sss;
YMD= new SYSTEMTIME;
GetLocalTime(YMD);
sss= String(YMD-> wYear)+String( "- ")+String(YMD-> wMonth)+String( "- ")+String(YMD-> wDay) ;
然后你读字符串SSS的值就行了。
我在给公司用C++ Builder做的数据库中调试通过了,
XP,2000都可以的。
也不用加其他的头文件。调用的是WINDOWS系统的咚咚。
我在VC6.0中 提示 AnsiString 没定义~
我在VC6.0中 提示 AnsiString 没定义~
…….
VC请用CString
Borland C++ builder请用AnsiString
如果你希望程序那里都可用
请用char *pCh = "time ";
#include <windows.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <assert.h>
#include "resource.h "
还是没定义
没有 CString 这个类 错误是 没有定义
进展的一点是 GetLocalTime(&systime); 可以获取系统时间
但是SYSTEMTIME 结构里变量是WORD 如果用MessageBox()显示出来的话 要把WORD转换成char型 现在问题就是转换了~ 偶不知道 高手多多指教哦~
也许是我记忆错误吧?
Cstring应该是有的…..
这几天休息的时候看完了一本小人书
里面有这么一段 我送给楼主
天才和高手到底有什么区别呢?
天才在错误发生之前可能会预见
高手呢?
高手则是在不断的调错排错中慢慢长大的
TDateTime t=Now();
t.DateString()); 日期
t.DateTimeString()); 时间
楼上的是用的MFC中的类~~ CSTRING 也是MFC中的 我只想知道 API里怎么把WORD类型转换为char类型~
大家在这里讨论也是一个交流的过程, 我并没有等着大家来解决,在这同时,我一直努力着~
另外 其实这个问题已经用另一个方法解决了 我想多学点东西 想问下 这个类型转换 是否能转~~
下面是实现代码
SetTextColor(hdc,RGB(0,255,0));
SetBkColor(hdc,RGB(0,0,0));
SetBkMode(hdc,OPAQUE);
sprintf(buffer, "Today is =( %d , %d ) ",systime.wYear,systime.wDay);
TextOut(hdc,0,75,buffer,strlen(buffer));
嘎嘎 貌似搞错达~~
取本机的:Now()
取服务器SQL:select getdate() as Rtime
包含Windows.h头文件即可!VC,BCB,Linux下通用。
//取系统时间
void XGetSystemDateTime(XSystemDateTime_s & s)
{
#if CONFIG_VC || CONFIG_BCB
SYSTEMTIME st;
GetSystemTime(&st);
s.Year = st.wYear;
s.Month = st.wMonth;
s.Day = st.wDay;
s.WeekDay = st.wDayOfWeek;
s.Hour = st.wHour;
s.Minute = st.wMinute;
s.Second = st.wSecond;
s.Milliseconds = st.wMilliseconds;
s.Zone = -480; //默认时区为东八区
TIME_ZONE_INFORMATION tz;
if(GetTimeZoneInformation(&tz) == TIME_ZONE_ID_STANDARD )
{
s.Zone = (XShort)tz.StandardBias;
}
#elif CONFIG_GCC
//throw XException( "在GCC下暂未实现 ");
struct timeval tv;
struct timezone tza;
gettimeofday(&tv,&tza);
s.Milliseconds = tv.tv_usec / 1000;
XInt tmp = tv.tv_sec;
s.Second = tmp % 60;
tmp /= 60;
s.Minute = tmp % 60;
tmp /= 60;
s.Hour = tmp % 24;
tmp /= 24;
tmp += DAYS_1970_1_1;
XInt iYear,iMonth,iDay;
DaysToDate(tmp,iYear,iMonth,iDay);
s.Year = iYear;
s.Month = iMonth;
s.Day = iDay;
s.WeekDay = tmp % 7;
s.Zone = tza.tz_minuteswest;
#else
throw XException( "未知编译器 ");
#endif
}
路过..标记.
//时间日期全有,写在TIMER里还可以动的,秒钟都能显示。
SYSTEMTIME *GTL =new SYSTEMTIME;
GetLocalTime(GTL);
lbldate-> Caption=String(GTL-> wYear)+ '- '+String(GTL-> wMonth)+ '- '+String(GTL-> wDay);
lbltime-> Caption=String(GTL-> wHour)+ ': '+String(GTL-> wMinute)+ ': '+String(GTL-> wSecond);
String Week[7]={ "星期日 ", "星期一 ", "星期二 ", "星期三 ", "星期四 ", "星期五 ", "星期六 "};
lblday-> Caption=Week[GTL-> wDayOfWeek];
该回复于2008-07-10 02:46:45被版主删除