首先把日期字符串转换成了一个日期型变量,如果StrToDateTime函数报错,则提示;如果没有错,则再用DateTimeToStr函数把日期型变量转换成标准格式,如'1999-12-31',这时候你就可以得到正确的年月日了。
另外,要定义你所想要的标准格式,预先设置全局变量ShortDateFormat。
另外,要定义你所想要的标准格式,预先设置全局变量ShortDateFormat。
解决方案 »
- 如何捕获tab键
- 在delphi中怎样删除DBImage对应记录的照片字段(二进制数据)?
- 我用idHppt去post一个网页,这个网页每次访问后自动跳转到的新网页才是我需要的。
- 各位大哥帮忙,给点意见,我该选用什么数据库呢?
- 请问,能不能在没有安装office的系统中,用delphi编程访问word,excel格式的文档
- 我使用了winamp那样的拖动客户窗体代码,但窗体上的按钮事件却无响应了!
- 有关打印的问题
- 急求 delphi 7 解析xml 数据
- 大家一起来讨论一下关于数据库的安全问题吧.(点数可以随时加,说得中肯的肯定给分!)
- 使用ADO的数据库操作是否可同时接受多个线程的调用。
- 随便帮我看看。。。。谢谢
- 小问题一个,在FileListbox1控件中,我选中了一条记录,如何点击Button2让FileListbox自动跳到下一条记录呀,每次只跳一条。
longtimeformat:= 'hh:mm:ss';
longdateformat:= 'yyyy''年''mm''月''dd''日''';
shortdateformat := 'yyyy-mm-dd';
twodigityearcenturywindow := 50;这样就保证了程序中的日期按你的要求显示。如果要分离日期的,可以使用
var
year,month,date :word;
decodedate(now,year,month,date)实现
date1:tdatetime;
year1,month1,day1:word;
begin
date1:=now; //取当前时间
decodedate(date1,year1,month1,day1);
qrly1.caption:=inttostr(year1); //年
qrlm1.caption:=inttostr(month1); //月
qrld1.caption:=inttostr(day1); //日
end;
DateString: string;
tempString: string;
i,CharLoc,lenthStr:integer;
myYear,myMon,MyDay:integer;
//……
//给DateString赋值 请保证你的日期是正确的哦,不要是“我0//9”之类的内容lengthStr:= StrLen(PChar(DateString));
for i:=1 to lengthStr do
begin
if (DateString[i]='-') or (DateString[i]='\')
then begin
CharLoc:=i;
break;
end;
end; tempString:=DateString;
delete(tempString,CharLoc,lengthStr-CharLoc+1); // 得到年的字符串
myYear:=StrToInt(tempString); //年年年年年年年年年年年年 delete(DateString,1,CharLoc); //去掉年 lengthStr:= StrLen(PChar(DateString));
for i:=1 to lengthStr do
begin
if (DateString[i]='-') or (DateString[i]='\')
then begin
CharLoc:=i;
break;
end;
end; tempString:=DateString; //与上面代码一样
delete(tempString,CharLoc,lengthStr-CharLoc+1); // 得到月的字符串
myMon:=StrToInt(tempString); //月月月月月月月月 delete(DateString,1,CharLoc); //去掉月 myDay:=StrToInt(DateString); //日日日日日日日日日日日日
function Pos(Substr: string; S: string): Integer;