100分请问: 想改变 TDateTimePicker中日期的显示为yymmdd的格式(100分)

  • 主题发起人 主题发起人 墨剑
  • 开始时间 开始时间

墨剑

Unregistered / Unconfirmed
GUEST, unregistred user!
100分请问: 想改变 TDateTimePicker中日期的显示为yymmdd的格式,如2004年5月1日在里面显示的是040501
 
在TDateTimePicker的format属性中输入yymmdd就可以了
 
TDateTimePicker.format='yymmdd';
 
楼主可以结贴了,答案很正确了呀
 
直接修改TDateTimePicker的dataformat属性为short就可以了
 
搞错没有? TDateTimePicker哪儿有什么format属性?
还有,angelloi,dataformat属性改为short只是变成短日期格式,根本不是我要的结果
大家继续。
 
FormatDateTime('yymmdd', Date)
 
datetimepicker1.Format:='yymmdd';
 
object Form1: TForm1
Left = 192
Top = 103
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
PixelsPerInch = 96
TextHeight = 13
object DateTimePicker1: TDateTimePicker
Left = 288
Top = 72
Width = 186
Height = 21
Date = 38124.764980567130000000
Format = 'yymmdd'
Time = 38124.764980567130000000
TabOrder = 0
end
end
 
to xuhao1:
拜托:没有尝试过你就不要乱发什么datetimepicker1.Format:='yymmdd'; 我都说了Tdatetimepicker没有这个属性
 
斑竹我们真的没有骗你,我用的是D6,里面真的有。绝对没有骗你得分。而且我也不该得分。我不会骗你吧。
 
我用的是delphi5,datetimepicker1没有format这个属性,其他版本的有没有我就不知道了。
 
delphi7有,但转换后月份数据错误,可能是bug
 
D5真的好久没有用了啊!不过要满足楼主的要求,D7也不行啊!还是必须自己动手写代码哦。楼主的要是是“2004年5月1日在里面显示的是040501”
 
TDateTimePicker.Format

Specify format for date-time string.

property Format: String;

Description

Format specifies custom format string for the date-time display, overriding the control panel strings. A custom format can include both date and time fields, but time fields are not editable unless the Kind property is dtkTime. The following format characters are understood.

Element Description
d The one- or two-digit day.
dd The two-digit day. Single-digit day values are preceded by a zero.
ddd The three-character weekday abbreviation.
dddd The full weekday name.
h The one- or two-digit hour in 12-hour format.
hh The two-digit hour in 12-hour format. Single-digit values are preceded by a zero.
H The one- or two-digit hour in 24-hour format.
HH The two-digit hour in 24-hour format. Single-digit values are preceded by a zero.

m The one- or two-digit minute.
mm The two-digit minute. Single-digit values are preceded by a zero.
M The one- or two-digit month number.
MM The two-digit month number. Single-digit values are preceded by a zero.
MMM The three-character month abbreviation.
MMMM The full month name.
t The one-letter AM/PM abbreviation (that is, AM is displayed as "A").
tt The two-letter AM/PM abbreviation (that is, AM is displayed as "AM").
yy The last two digits of the year (that is, 2001 would be displayed as "01").

yyyy The full year (that is, 2001 would be displayed as "2001").

To include literal strings in the format, enclose them in single quotes. Failing to quote literal strings can have unpredicable results, even if they do not include formatting codes. Use two single quotes to represent one single quote character in literal string. For example,

'Today''s date:' MMM dd, yyyy

formatted for the first day of April, 2001, would display "Today's date: Apr 01, 2001".
 
不讨论format的问题了。 我们看看能不能编写一个combobox,然后在下拉的时候弹出像
datetimepicker那样的日期选择窗口
 
用这个函数
edit1.text:=formatdatetime('yymmdd',now);

edit1.text的值 是 040517
04年5月17日
 
函数如下:
function FormatDateTime(const Format: string; DateTime: TDateTime): string;
别忘了给分阿!
把你的tdatetimepicker.date放进去就行了。
 
function tform1.zhuanhuan(s2:string):string;
begin
if length(s2)=1 then
s2:='0'+s2;
result:=s2;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
date1:tdatetime;
Year, Month, Day, Hour, Min, Sec, MSec: Word;
s1:string;
begin
date1:=tdatetimepicker1.date;
DecodeDate(date1, Year, Month, Day);
s1:=copy(inttostr(year),3,2)+zhuanhuan(inttostr(month))+zhuanhuan(inttostr(day));
end;
 
别误会,我的意思是tedit或tcombobox与tdatetimepicker1成为一个整体,而不是分开的控件。在需要的地方直接把这个控件拿出来就行了,不用再写代码
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
1K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
922
SUNSTONE的Delphi笔记
S
S
回复
0
查看
1K
swish
S
后退
顶部