看一下这个过程,DecodeDate,应该会有收获的!DecodeDate procedureDecodeDate breaks TDateTime into Year, Month, and Day values.UnitSysUtilsCategorydate/time routinesprocedure DecodeDate(Date: TDateTime; var Year, Month, Day: Word);DescriptionThe DecodeDate procedure breaks the value specified as the Date parameter into Year, Month, and Day values. If the given TDateTime value is less than or equal to zero, the year, month, and day return parameters are all set to zero.
解决方案 »
- delphi base64编码图片字符串转化图片显示IMAGE
- 八百里加急,急需各位大侠的帮助!!(在线等待)
- 一个想不通的问题:为什么打印预览的记录数随打印机驱动的不同而不同?
- 怎么判断用户输入的日期是否合法?
- 一个很菜的问题,请大家帮忙!!
- postmessage一个空格按下的消息
- 谁知道WIN2000下QQ运行机制!
- 如何改变ListView中指定那行的颜色?
- 调用ShellExecute要引用哪个单元?我在帮助里找不到.
- 高手请进!请问这是 Delphi5的Bug吗?
- 我想问一个问题:我要想学学控件的写法,
- 奇怪的问题,在创建不规则窗体时。有兴趣进来看看(难道是delphi的bug??????)
Present: TDateTime;
Year, Month, Day, Hour, Min, Sec, MSec: Word;
begin
Present:= Now;
DecodeDate(Present, Year, Month, Day);
Label1.Caption := 'Today is Day ' + IntToStr(Day) + ' of Month '
+ IntToStr(Month) + ' of Year ' + IntToStr(Year);
DecodeTime(Present, Hour, Min, Sec, MSec);
Label2.Caption := 'The time is Minute ' + IntToStr(Min) + ' of Hour '
+ IntToStr(Hour);
end;
可以直接把日期字符串分解成年月日啊
decodedate(date,year,month,day)
#include <stdio.h>
#include <string.h>
char string[] = "A string\tof ,,tokens\nand some more tokens";
char seps[] = " ,\t\n";
char *token;void main( void )
{
printf( "%s\n\nTokens:\n", string );
/* Establish string and get the first token: */
token = strtok( string, seps );
while( token != NULL )
{
/* While there are tokens in "string" */
printf( " %s\n", token );
/* Get next token: */
token = strtok( NULL, seps );
}
}
int CHousingView::GetYear(CString str)
{
if(str=="") return 0;
int i;
TCHAR str1;
CString str2="";
i=str.Find("年");
for(int j=0;j<i;j++)
{
str1=str.GetAt(j);
str2=str2+str1;
}
return atoi(str2);}int CHousingView::GetDay(CString str)
{
if(str=="") return 0;
int i,k;
TCHAR str1;
CString str2="";
i=str.Find("月");
k=str.Find("日");
for(int j=i+2;j<k;j++)
{
str1=str.GetAt(j);
str2=str2+str1;
}
return atoi(str2);}
int CHousingView::GetMonth(CString str)
{
if(str=="") return 0;
int i,k;
TCHAR str1;
CString str2="";
i=str.Find("年");
k=str.Find("月");
for(int j=i+2;j<k;j++)
{
str1=str.GetAt(j);
str2=str2+str1;
}
return atoi(str2);}
function Pos(Substr: string; S: string): Integer;
var
Present: TDateTime;
Year, Month, Day, Hour, Min, Sec, MSec: Word;
sDateTime :string;
begin
sDateTime := '01/01/11';
Present:= StrToDateTime(sDateTime);
DecodeDate(Present, Year, Month, Day);
Label1.Caption := 'Today is Day ' + IntToStr(Day) + ' of Month '
+ IntToStr(Month) + ' of Year ' + IntToStr(Year);
DecodeTime(Present, Hour, Min, Sec, MSec);
Label2.Caption := 'The time is Minute ' + IntToStr(Min) + ' of Hour '
+ IntToStr(Hour);
end;
procedure getYMDfromStr(datestr:string;var y,m,d:string);
var tmpstr:string;
i,count:integer;
begin
for i:=1 to 2 do
begin
count:=pos('/',datestr);
if count<0 then exit;
tmpstr:=copy(datestr,1,count-1);
case i of
1:y:=tmpstr;
2:m:=tmpstr;
end;
delete(datestr,1,count);
end;
d:=datestr;
end;
procedure TForm1.Button1Click(Sender: TObject);
var y,m,d:string;
begin
getymdfromstr(edit1.Text,y,m,d);
showmessage('y:'+y+'m:'+m+'d:'+d);
end;
用如下方法也可以实现:
str:='01/2/3'
var
test:tstringlist;
begin
try
test:=tstringlist.create;
test.text:=stringreplace(str,'/',chr(10),[rfReplaceAll]);
showmessage(test[1]);
finally
test.free;
end;
end;