제가 Builder 5.0을 사용하고 있는데
#include "DateUtils.hpp" 를 찾을수가 없습니다.
5.0에는 파일이 없는건가요?
장성호 님이 쓰신 글 :
: 너브님께서 링크해주신 곳에는 DateTime의 자료형에 대해 나와있습니다.
: 읽어보시고 이해를 해두시는것이 좋을거 같습니다.
:
: 그리고 하나더 말씀드리면 VCL에는 DateUtils라는 datetime관련 라이브러리를 제공합니다.
:
: #include "DateUtils.hpp" 하시면 됩니다.
:
: 그기에 보면 YearsBetween , MonthsBetween .... 등등
: 년 , 월 , 일 , 시간 등의 차이를 구하는 함수가 있습니다.
:
:
: #include "DateUtils.hpp"
:
: //extern PACKAGE int __fastcall YearsBetween(const System::TDateTime ANow, const System::TDateTime AThen);
: //extern PACKAGE int __fastcall MonthsBetween(const System::TDateTime ANow, const System::TDateTime AThen);
: //extern PACKAGE int __fastcall WeeksBetween(const System::TDateTime ANow, const System::TDateTime AThen);
: //extern PACKAGE int __fastcall DaysBetween(const System::TDateTime ANow, const System::TDateTime AThen);
: //extern PACKAGE __int64 __fastcall HoursBetween(const System::TDateTime ANow, const System::TDateTime AThen);
: //extern PACKAGE __int64 __fastcall MinutesBetween(const System::TDateTime ANow, const System::TDateTime AThen);
: //extern PACKAGE __int64 __fastcall SecondsBetween(const System::TDateTime ANow, const System::TDateTime AThen);
: //extern PACKAGE __int64 __fastcall MilliSecondsBetween(const System::TDateTime ANow, const System::TDateTime AThen);
:
: void __fastcall TForm1::Button1Click(TObject *Sender)
: {
: //
: String A = "2008-09-01 23:00:00" ;
: String B = "2008-09-02 03:00:00" ;
:
: TDateTime dtA,dtB,dtC,dtD;
: dtA=StrToDateTime(A);
: dtB=StrToDateTime(B);
: dtC.Val=0; //기준날짜
:
: ShowMessage("TDateTime의 Val이 0일때는 날짜가 : '"+dtC.DateTimeString()+"' 입니다. " );
:
: if(dtA.Val>dtB.Val) dtD.Val=dtA.Val-dtB.Val;
: else dtD.Val=dtB.Val-dtA.Val;
:
: int iY=YearsBetween(dtD,dtC);
: int iM=MonthsBetween(dtD,dtC);
: int iD=DaysBetween(dtD,dtC);
: int iH=HoursBetween(dtD,dtC);
:
: dtD =IncHour(dtD,-iH); // 또는 dtD.Val=dtD.Val - iH /24.0;
: int iMi=MinutesBetween(dtD,dtC);
:
: dtD = IncMinute(dtD,-iMi);// 또는 dtD.Val=dtD.Val - iMi /(24*60.0);
:
: int iSec= SecondsBetween(dtD,dtC);
:
: String s;
: s.sprintf("'%s' 와 '%s'의 차이는 \r\n\r\n %d년 %d월 %d일 %d시간 %d분 %d초 가 차이납니다.",A,B,iY,iM,iD,iH,iMi,iSec);
: ShowMessage(s);
:
: }
:
:
:
:
: 딱 4시간으로 떨어지지 않는것은 실수형 연산이라 그렇겠죠
: 그러니 날짜,시간 까지는 모르겠는데 그 이하는 String으로 연산하는것이 더 정확할것 같습니다.
:
: 그럼..
:
:
: 너브 님이 쓰신 글 :
: :
http://cbuilder.borlandforum.com/impboard/impboard.dll?action=read&db=bcb_qna&no=54179
: :
: : 위에 잘 나와 있네요....^^
: :
: : 조금만 응용하면 될거 같네요...^^
: :
: :
: :
: : 30억 님이 쓰신 글 :
: : : A = "2008-09-01 23:00:00" ;
: : : B = "2008-09-02 03:00:00" ;
: : :
: : : -> 3시간
: : :
: : : B날짜에서 A날짜의 시간차이를 구하고 싶습니다.
: : : 고수님들의 조언부탁드립니다.