全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:1973
推到 Plurk!
推到 Facebook!

如何設定TDateTime的時間?

答題得分者是:RaynorPao
wivern
初階會員


發表:31
回覆:63
積分:28
註冊:2002-07-31

發送簡訊給我
#1 引用回覆 回覆 發表時間:2003-09-01 18:19:33 IP:61.219.xxx.xxx 未訂閱
我想請問一下,我定義了一個TDateTime的變數, 要如何設定這個變數的年、月、日、時、分、秒呢? 像是設成2003/09/20 17:38:49.389 之類的~ 麻煩各位解答一下,謝謝~
RaynorPao
版主


發表:139
回覆:3622
積分:7025
註冊:2002-08-12

發送簡訊給我
#2 引用回覆 回覆 發表時間:2003-09-01 20:00:52 IP:61.221.xxx.xxx 未訂閱
引言: 我想請問一下,我定義了一個TDateTime的變數, 要如何設定這個變數的年、月、日、時、分、秒呢? 像是設成2003/09/20 17:38:49.389 之類的~ 麻煩各位解答一下,謝謝~
wivern 你好: 可以利用 EncodeDateTime 這個 function 來達成目的
#include "DateUtils.hpp"
   TDateTime dt;
   dt=EncodeDateTime(2003, 9, 20, 17, 38, 49, 389);
   ShowMessage(dt);
-- Enjoy Researching & Developing --
------
-- 若您已經得到滿意的答覆,請適時結案!! --
-- 欲知前世因,今生受者是;欲知來世果,今生做者是 --
-- 一切有為法,如夢幻泡影,如露亦如電,應作如是觀 --
wivern
初階會員


發表:31
回覆:63
積分:28
註冊:2002-07-31

發送簡訊給我
#3 引用回覆 回覆 發表時間:2003-09-02 08:52:40 IP:61.219.xxx.xxx 未訂閱
謝謝!! 不過我試的結果,怎麼沒辦法成功呢? 以下是我的程式碼:  
#include 
#include "DateUtils.hpp"
#pragma hdrstop
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
void __fastcall TForm1::Button1Click(TObject *Sender)
{
TDateTime date;
short current_year,current_month,current_day,current_hour,current_minute,current_second;    date==EncodeDateTime(2003, 9, 20, 17, 38, 49, 389);
//ShowMessage(date);    current_year=date.FormatString("yyyy").ToInt();
current_month=date.FormatString("mm").ToInt();
current_day=date.FormatString("dd").ToInt();
current_hour=date.FormatString("hh").ToInt();
current_minute=date.FormatString("nn").ToInt();
current_second=date.FormatString("ss").ToInt();
Edit1->Text=IntToStr(current_year)   "/" IntToStr(current_month)   "/" IntToStr(current_day)   " " IntToStr(current_hour) ":" 
  IntToStr(current_minute)   ":"   IntToStr(current_second);
}
結果我按下按鈕之後,Edit1的內容是1899/12/30 0:0:0 這是怎麼回事呢?? 發表人 - wivern 於 2003/09/02 09:09:49
李國維
高階會員


發表:42
回覆:287
積分:235
註冊:2003-02-07

發送簡訊給我
#4 引用回覆 回覆 發表時間:2003-09-02 11:26:58 IP:211.22.xxx.xxx 未訂閱
基本上用EncodeDateTime沒錯.. 但是我看你ㄉsource code有一各怪怪ㄉ地方 就是'date==EncodeDateTime(2003, 9, 20, 17, 38, 49, 389);'這行 因為==是比較式他不會把值互傳.只會傳回真假.. 你要用=才對吧...    
引言: 謝謝!! 不過我試的結果,怎麼沒辦法成功呢? 以下是我的程式碼:
#include 
#include "DateUtils.hpp"
#pragma hdrstop
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
void __fastcall TForm1::Button1Click(TObject *Sender)
{
TDateTime date;
short current_year,current_month,current_day,current_hour,current_minute,current_second;    date==EncodeDateTime(2003, 9, 20, 17, 38, 49, 389);
//ShowMessage(date);    current_year=date.FormatString("yyyy").ToInt();
current_month=date.FormatString("mm").ToInt();
current_day=date.FormatString("dd").ToInt();
current_hour=date.FormatString("hh").ToInt();
current_minute=date.FormatString("nn").ToInt();
current_second=date.FormatString("ss").ToInt();
Edit1->Text=IntToStr(current_year)   "/" IntToStr(current_month)   "/" IntToStr(current_day)   " " IntToStr(current_hour) ":" 
  IntToStr(current_minute)   ":"   IntToStr(current_second);
}
結果我按下按鈕之後,Edit1的內容是1899/12/30 0:0:0 這是怎麼回事呢?? 發表人 - wivern 於 2003/09/02 09:09:49
wivern
初階會員


發表:31
回覆:63
積分:28
註冊:2002-07-31

發送簡訊給我
#5 引用回覆 回覆 發表時間:2003-09-02 11:39:47 IP:61.219.xxx.xxx 未訂閱
啊...,原來是我自己耍白痴...多打了一個'='.. 真是不好意思!!謝謝你!!    
引言: 基本上用EncodeDateTime沒錯.. 但是我看你ㄉsource code有一各怪怪ㄉ地方 就是'date==EncodeDateTime(2003, 9, 20, 17, 38, 49, 389);'這行 因為==是比較式他不會把值互傳.只會傳回真假.. 你要用=才對吧...
引言: 謝謝!! 不過我試的結果,怎麼沒辦法成功呢? 以下是我的程式碼:
#include 
#include "DateUtils.hpp"
#pragma hdrstop
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
void __fastcall TForm1::Button1Click(TObject *Sender)
{
TDateTime date;
short current_year,current_month,current_day,current_hour,current_minute,current_second;    date==EncodeDateTime(2003, 9, 20, 17, 38, 49, 389);
//ShowMessage(date);    current_year=date.FormatString("yyyy").ToInt();
current_month=date.FormatString("mm").ToInt();
current_day=date.FormatString("dd").ToInt();
current_hour=date.FormatString("hh").ToInt();
current_minute=date.FormatString("nn").ToInt();
current_second=date.FormatString("ss").ToInt();
Edit1->Text=IntToStr(current_year)   "/" IntToStr(current_month)   "/" IntToStr(current_day)   " " IntToStr(current_hour) ":" 
  IntToStr(current_minute)   ":"   IntToStr(current_second);
}
結果我按下按鈕之後,Edit1的內容是1899/12/30 0:0:0 這是怎麼回事呢?? 發表人 - wivern 於 2003/09/02 09:09:49
系統時間:2024-09-29 9:02:31
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!