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

如何將目前的時間塞入 timestmp

答題得分者是:dllee
david629
一般會員


發表:50
回覆:25
積分:15
註冊:2003-02-14

發送簡訊給我
#1 引用回覆 回覆 發表時間:2003-05-01 15:45:02 IP:211.22.xxx.xxx 未訂閱
struct timestamp { UINT16 typeAndTimezone; INT16 year; UINT8 month; UINT8 day; UINT8 hour; UINT8 minute; UINT8 second; UINT8 centiseconds; UINT8 hundredsOfMicroseconds; UINT8 microseconds; }; 要如何取得目前的時間(精度要到 microseconds)並塞給 timestanp 內呢??
BGman
初階會員


發表:28
回覆:85
積分:42
註冊:2003-01-10

發送簡訊給我
#2 引用回覆 回覆 發表時間:2003-05-01 16:17:52 IP:211.22.xxx.xxx 未訂閱
Hi David 桑:請使用 DateTimeToTimeStamp 函式 函式規格如下: 功能 Converts a TDateTime object into the corresponding TTimeStamp structure. 來源 Unit : Sysutils ; Category : date/time routines 使用 extern PACKAGE TTimeStamp __fastcall DateTimeToTimeStampSystem::TDateTime DateTime);
dllee
站務副站長


發表:321
回覆:2519
積分:1711
註冊:2002-04-15

發送簡訊給我
#3 引用回覆 回覆 發表時間:2003-05-01 16:19:44 IP:61.224.xxx.xxx 未訂閱
用 TDateTime 即可,如: TDateTime dt=Now(); unsigned short year,month,day; unsigned short hour,min,sec,msec; dt.DecodeDate(&year,&month,&day); dt.DecodeTime(&hour,&min,&sec,&msec);        沒空更新的網頁... http://dllee.ktop.com.tw C及指標教學,計算機概論,資訊管理導論... http://big5.to/吃軟也吃硬 http://coolsite.to/ushells 介紹Shells,LiteStep,GeoShell....
------
http://www.ViewMove.com
dllee
站務副站長


發表:321
回覆:2519
積分:1711
註冊:2002-04-15

發送簡訊給我
#4 引用回覆 回覆 發表時間:2003-05-01 16:33:31 IP:61.224.xxx.xxx 未訂閱
哇!幾乎同時回答...    我剛查了一下 TTimeStamp 的資料結構是:
struct TTimeStamp
{
  int Time;
  int Date;
} ;
其中 Time 是自零時(00:00:00.000)起算到目前的 mSec 數,而 Date 則是自 西元 1 年 1 月 1 日 到現在的日數。 如果要取得年月日時分秒,還是用 TDateTime 的 DecodeDate/Time 比較快,如果只是要記錄一個 TimeStamp 日後再來計算出當時的年月日時分秒,那用 TTimeStamp 來存比較快,因只占 8 bytes 儲存空間較省。如此,用 TTimeStamp ts=DateTimeToTimeStamp(Now()); // 取得目前 TimeStamp ... TDateTime dt=TimeStampToDateTime(ts); // TimeStamp 轉 TDateTime 以便顯示 Label1->Caption=dt.FormatString("yyyy-mm-dd hh:nn:ss"); 沒空更新的網頁... http://dllee.ktop.com.tw C及指標教學,計算機概論,資訊管理導論... http://big5.to/吃軟也吃硬 http://coolsite.to/ushells 介紹Shells,LiteStep,GeoShell....
------
http://www.ViewMove.com
david629
一般會員


發表:50
回覆:25
積分:15
註冊:2003-02-14

發送簡訊給我
#5 引用回覆 回覆 發表時間:2003-05-01 16:41:50 IP:211.22.xxx.xxx 未訂閱
引言: 哇!幾乎同時回答... 我剛查了一下 TTimeStamp 的資料結構是:
struct TTimeStamp
{
  int Time;
  int Date;
} ;
其中 Time 是自零時(00:00:00.000)起算到目前的 mSec 數,而 Date 則是自 西元 1 年 1 月 1 日 到現在的日數。 如果要取得年月日時分秒,還是用 TDateTime 的 DecodeDate/Time 比較快,如果只是要記錄一個 TimeStamp 日後再來計算出當時的年月日時分秒,那用 TTimeStamp 來存比較快,因只占 8 bytes 儲存空間較省。如此,用 TTimeStamp ts=DateTimeToTimeStamp(Now()); // 取得目前 TimeStamp ... TDateTime dt=TimeStampToDateTime(ts); // TimeStamp 轉 TDateTime 以便顯示 Label1->Caption=dt.FormatString("yyyy-mm-dd hh:nn:ss"); 沒空更新的網頁... http://dllee.ktop.com.tw C及指標教學,計算機概論,資訊管理導論... http://big5.to/吃軟也吃硬 http://coolsite.to/ushells 介紹Shells,LiteStep,GeoShell....
如果還要知道當下的 centiseconds hundredsOfMicroseconds microseconds 要怎麼取得呢 ??
dllee
站務副站長


發表:321
回覆:2519
積分:1711
註冊:2002-04-15

發送簡訊給我
#6 引用回覆 回覆 發表時間:2003-05-01 16:56:27 IP:61.224.xxx.xxx 未訂閱
引言: 如果還要知道當下的 centiseconds hundredsOfMicroseconds microseconds 要怎麼取得呢 ??
我正想要問您為什麼有這些欄位?一般在秒以下就取 mSec 了,是還要再細分嗎? 如果是,那之前已取得的 msec 就是以 microseconds 為單位了,而再細分則是取出每一位,如下: centiseconds=msec/100; hundredsOfMicroseconds=(msec/10) % 10; microseconds=msec % 10; 有必要分那麼細嗎? 沒空更新的網頁... http://dllee.ktop.com.tw C及指標教學,計算機概論,資訊管理導論... http://big5.to/吃軟也吃硬 http://coolsite.to/ushells 介紹Shells,LiteStep,GeoShell....
------
http://www.ViewMove.com
david629
一般會員


發表:50
回覆:25
積分:15
註冊:2003-02-14

發送簡訊給我
#7 引用回覆 回覆 發表時間:2003-05-01 17:13:40 IP:211.22.xxx.xxx 未訂閱
以下列出 c 語言下的程式,其中兩行我不會用轉不成 BCB 謝謝!! struct timeval { long tv_sec; long tv_usec; }; struct timezone { int tz_minuteswest; int tz_dsttime; }; struct tm { int tm_sec; int tm_min; int tm_hour; int tm_mday; int tm_mon; int tm_year; int tm_wday; int tm_yday; int tm_isdst; } timestamp ts; struct timeval tv; struct tm *tm; int altzone; gettimeofday(&tv, NULL); <======== 不會用 BCB 轉 tm = localtime(&tv.tv_sec); <======== 不會用 BCB 轉 altzone = timezone - 3600; if (daylight) ts.typeAndTimezone = cpu_to_le16(((-altzone/60) & 0x0FFF) | 0x1000); else ts.typeAndTimezone = cpu_to_le16(((-timezone/60) & 0x0FFF) | 0x1000); // 設定時間 ts.year = cpu_to_le16(1900 tm->tm_year); ts.month = 1 tm->tm_mon; ts.day = tm->tm_mday; ts.hour = tm->tm_hour; ts.minute = tm->tm_min; ts.second = tm->tm_sec; ts.centiseconds = tv.tv_usec / 10000; ts.hundredsOfMicroseconds = (tv.tv_usec - ts.centiseconds * 10000) / 100; ts.microseconds = tv.tv_usec - ts.centiseconds * 10000 - ts.hundredsOfMicroseconds * 100;
dllee
站務副站長


發表:321
回覆:2519
積分:1711
註冊:2002-04-15

發送簡訊給我
#8 引用回覆 回覆 發表時間:2003-05-01 17:30:15 IP:61.224.xxx.xxx 未訂閱
不需要那兩行,改成您最後需要設定的日期時間就都有了。    TDateTime dt=Now(); unsigned short year,month,day; unsigned short hour,min,sec,msec; dt.DecodeDate(&year,&month,&day); dt.DecodeTime(&hour,&min,&sec,&msec);    centiseconds=msec/100; hundredsOfMicroseconds=(msec/10) % 10; microseconds=msec % 10;    沒空更新的網頁... http://dllee.ktop.com.tw C及指標教學,計算機概論,資訊管理導論... http://big5.to/吃軟也吃硬 http://coolsite.to/ushells 介紹Shells,LiteStep,GeoShell....
------
http://www.ViewMove.com
david629
一般會員


發表:50
回覆:25
積分:15
註冊:2003-02-14

發送簡訊給我
#9 引用回覆 回覆 發表時間:2003-05-01 17:45:17 IP:211.22.xxx.xxx 未訂閱
引言: 不需要那兩行,改成您最後需要設定的日期時間就都有了。 TDateTime dt=Now(); unsigned short year,month,day; unsigned short hour,min,sec,msec; dt.DecodeDate(&year,&month,&day); dt.DecodeTime(&hour,&min,&sec,&msec); centiseconds=msec/100; hundredsOfMicroseconds=(msec/10) % 10; microseconds=msec % 10; 沒空更新的網頁... http://dllee.ktop.com.tw C及指標教學,計算機概論,資訊管理導論... http://big5.to/吃軟也吃硬 http://coolsite.to/ushells 介紹Shells,LiteStep,GeoShell....
感謝!!
系統時間:2024-05-07 21:39:15
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!