線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:2130
推到 Plurk!
推到 Facebook!

關於日期

答題得分者是:salo0610
zx4654
一般會員


發表:18
回覆:26
積分:8
註冊:2005-04-05

發送簡訊給我
#1 引用回覆 回覆 發表時間:2008-04-22 15:14:11 IP:118.170.xxx.xxx 訂閱
請教各位,我現在有一個程式需要昨天的日期,我原本用Now()減一,後來突然想到如果是一號,就很多問題了,請問我該如何處理,另外我找不到TDateTime 這是元件嗎?
salo0610
高階會員


發表:42
回覆:120
積分:107
註冊:2003-02-18

發送簡訊給我
#2 引用回覆 回覆 發表時間:2008-04-22 16:20:00 IP:220.132.xxx.xxx 未訂閱
   我測 ok 啊, 一號時,Now()-1  也會 變成 前一個月的最後一天啊

TDate a = Now();
TDate b = Now()-1;
unsigned short yy;
unsigned short mm;
unsigned short dd;
a.DecodeDate(&yy,&mm,&dd);
ShowMessage( String(yy) String(mm) String(dd) );
b.DecodeDate(&yy,&mm,&dd);
ShowMessage( String(yy) String(mm) String(dd) );
salo0610
高階會員


發表:42
回覆:120
積分:107
註冊:2003-02-18

發送簡訊給我
#3 引用回覆 回覆 發表時間:2008-04-22 16:20:57 IP:220.132.xxx.xxx 未訂閱

TDateTime is the C analog for the Object Pascal TDateTime data type.
Header
systdate.h
Description
TDateTime implements the Object Pascal TDateTime data type and the date/time runtime library routines that use the TDateTime data type.
The TDateTime class inherits a val data member declared as a double that holds the date-time value. The integral part of a TDateTime value is the number of days that have passed since 12/30/1899. The fractional part of a TDateTime value is the time of day.
Following are some examples of TDateTime values and their corresponding dates and times:
0 12/30/1899 12:00 am
2.75 1/1/1900 6:00 pm
-1.25 12/29/1899 6:00 am
35065 1/1/1996 12:00 am
To find the fractional number of days between two dates, simply subtract the two values, unless one of the TDateTime values is negative. Similarly, to increment a date and time value by a certain fractional number of days, add the fractional number to the date and time value if the TDateTime value is positive.
When working with negative TDateTime values, computations must handle time portion separately. The fractional part reflects the fraction of a 24-hour day without regard to the sign of the TDateTime value. For example, 6:00 am on 12/29/1899 is ?.25, not ? 0.25, which would be ?.75. There are no TDateTime values between ? and 0.
Note: Use only the operators declared by TDateTime. The compiler ignores any operators you overload yourself.
Warning: It is not possible to use TDateTime as a base class for inheriting. To add functionality to TDateTime, you must write a wrapper class.
Note: If you #include or #define VCL_IOSTREAM before the include statement for systdate.h (which is typically included indirectly via vcl.h), you can use the streaming operators (<< and >>) with TDateTime values as an argument:
ostream& operator << (ostream& os, const TDateTime& arg);
istream& operator >> (istream& is, TDateTime& arg);
zx4654
一般會員


發表:18
回覆:26
積分:8
註冊:2005-04-05

發送簡訊給我
#4 引用回覆 回覆 發表時間:2008-04-22 16:23:43 IP:118.170.xxx.xxx 訂閱

===================引 用 salo0610 文 章===================
我測 ok 啊, 一號時,Now()-1 也會 變成 前一個月的最後一天啊

TDate a = Now();
TDate b = Now()-1;
unsigned short yy;
unsigned short mm;
unsigned short dd;
a.DecodeDate(&yy,&mm,&dd);
ShowMessage( String(yy) String(mm) String(dd) );
b.DecodeDate(&yy,&mm,&dd);
ShowMessage( String(yy) String(mm) String(dd) );

謝謝你,我剛試了的確可以。不過我用的是Now().operator --().FormatString("yyyymmdd")搞定了,感謝你的熱心。
系統時間:2024-04-19 16:02:33
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!