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

Datetimepicker要顯示label時,年月日可以固定為8碼

答題得分者是:pceyes
od11112001
一般會員


發表:8
回覆:2
積分:2
註冊:2008-08-04

發送簡訊給我
#1 引用回覆 回覆 發表時間:2008-10-06 13:49:59 IP:140.128.xxx.xxx 訂閱

我們在測一個程式
是希望我們只要自已點月曆的日期時
它就會自動顯示在label內
如2008年1月1日
顯示可為20080101
現在我們可以顯示較正常的
如2008年10年10日
但是在單月或是單日時
該如何讓寫顯示為8碼的日期?

然後因為我們想分三個時段
為早、午、晚
並以a、b、c來表示
是要直接結合時間來顯示
如20081010a
就是2008年10月10日的早上

請問這樣程式
要怎麼寫呢?

謝謝!

------
hi
編輯記錄
taishyang 重新編輯於 2008-10-08 19:25:06, 註解 歸類成[問題]‧
careychen
尊榮會員


發表:41
回覆:580
積分:959
註冊:2004-03-03

發送簡訊給我
#2 引用回覆 回覆 發表時間:2008-10-06 14:30:36 IP:218.210.xxx.xxx 訂閱
要顯示成妳的時間格式,可以用 formatdatetime('yyyymmdd', now)  

這個... 有點要碎碎念一下,妳的上一篇的內容其實可以解決妳現在 PO 的問題,但這篇只是換個方法再問一次
而且妳這篇的類別應該是【問題】,不是【討論】,請修改一下哦!!


===================引 用 od11112001 文 章===================

我們在測一個程式
是希望我們只要自已點月曆的日期時
它就會自動顯示在label內
如2008年1月1日
顯示可為20080101
現在我們可以顯示較正常的
如2008年10年10日
但是在單月或是單日時
該如何讓寫顯示為8碼的日期?

然後因為我們想分三個時段
為早、午、晚
並以a、b、c來表示
是要直接結合時間來顯示
如20081010a
就是2008年10月10日的早上

請問這樣程式
要怎麼寫呢?

謝謝!

------
價值的展現,來自於你用哪一個角度來看待它!!
pceyes
尊榮會員


發表:70
回覆:657
積分:1140
註冊:2003-03-13

發送簡訊給我
#3 引用回覆 回覆 發表時間:2008-10-06 15:55:55 IP:122.118.xxx.xxx 訂閱
Unit1.pas

[code delphi]
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ComCtrls, ExtCtrls;

type
TForm1 = class(TForm)
Label2: TLabel;
Label3: TLabel;
RadioGroup1: TRadioGroup;
GroupBox1: TGroupBox;
MonthCalendar1: TMonthCalendar;
Panel1: TPanel;
Label1: TLabel;
procedure MonthCalendar1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure RadioGroup1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
Date8 : string;
APM : string;

implementation
{$R *.dfm}
procedure TForm1.MonthCalendar1Click(Sender: TObject);
BEGIN
Date8 := formatdatetime('YYYYMMDD',MonthCalendar1.Date);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
Date8 := formatdatetime('YYYYMMDD',Now); // 顯示今天的日期
APM := '';
RadioGroup1.ItemIndex := -1;
end;

procedure TForm1.RadioGroup1Click(Sender: TObject);
begin
case RadioGroup1.ItemIndex of
0:
APM := 'a';
1:
APM := 'b';
2:
APM := 'c';
end;
// 日期 加上 時間
if (Date8 <> '')and(APM <> '') then begin
label1.Caption := Date8 APM;
end;
end;

end.

[/code]
Unit1.dfm

[code delphi]
object Form1: TForm1
Left = 192
Top = 114
Width = 696
Height = 480
Caption = 'Form1'
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = False
OnCreate = FormCreate
PixelsPerInch = 96
TextHeight = 13
object Label2: TLabel
Left = 16
Top = 16
Width = 34
Height = 48
Caption = '1.'
Font.Charset = ANSI_CHARSET
Font.Color = clMaroon
Font.Height = -48
Font.Name = '新細明體'
Font.Style = []
ParentFont = False
end
object Label3: TLabel
Left = 408
Top = 16
Width = 34
Height = 48
Caption = '2.'
Font.Charset = ANSI_CHARSET
Font.Color = clMaroon
Font.Height = -48
Font.Name = '新細明體'
Font.Style = []
ParentFont = False
end
object RadioGroup1: TRadioGroup
Left = 472
Top = 72
Width = 153
Height = 273
Caption = '請選擇時段'
Font.Charset = CHINESEBIG5_CHARSET
Font.Color = clWindowText
Font.Height = -21
Font.Name = '新細明體'
Font.Style = []
Items.Strings = (
'早'
'午'
'晚')
ParentFont = False
TabOrder = 0
OnClick = RadioGroup1Click
end
object GroupBox1: TGroupBox
Left = 8
Top = 56
Width = 439
Height = 291
Caption = '請選擇日期'
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -21
Font.Name = 'MS Sans Serif'
Font.Style = []
ParentFont = False
TabOrder = 1
object MonthCalendar1: TMonthCalendar
Left = 2
Top = 26
Width = 435
Height = 263
Align = alClient
Date = 39727.659991319440000000
TabOrder = 0
OnClick = MonthCalendar1Click
end
end
object Panel1: TPanel
Left = 0
Top = 349
Width = 688
Height = 97
Align = alBottom
Caption = 'Panel1'
TabOrder = 2
object Label1: TLabel
Left = 1
Top = 1
Width = 686
Height = 95
Align = alClient
Alignment = taCenter
Caption = '顯示區'
Font.Charset = ANSI_CHARSET
Font.Color = clWindowText
Font.Height = -96
Font.Name = '新細明體'
Font.Style = [fsBold]
ParentFont = False
end
end
end

[/code]

------
努力會更接近成功
系統時間:2024-05-05 4:01:23
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!