internet上得到的时间字符串12:13:54 2002-9-24,如何转化为tdatetime型,如果不截取字符串的话

michael_king 2002-09-24 12:26:36
我这样做觉得太繁了,有人知道简单的吗?
procedure TForm1.FormCreate(Sender: TObject);
var
NMDayTime1: TNMDayTime;
currentTime:TSystemTime;
i:integer;
str:String;
begin
NMDayTime1:=TNMDayTime.Create(self);
NMDayTime1.Host:='202.109.114.209';
NMDayTime1.Port:=13;
Label1.Caption:=NMDayTime1.DayTimeStr;
Edit1.Text:=Label1.Caption;
str:=copy(Label1.Caption,0,8);
DecodeTime(StrToTime(str),CurrentTime.wHour,CurrentTime.wMinute,
CurrentTime.wSecond,CurrentTime.wMilliseconds);
str:=copy(Label1.Caption,10,Length(Label1.Caption)-7);
DecodeDate(StrToDate(trim(str)),CurrentTime.wYear,CurrentTime.wMonth,
CurrentTime.wDay);
SetLocaltime(currentTime);
NMDayTime1.Destroy;
end;
...全文
44 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
日总是我哥 2002-09-24
  • 打赏
  • 举报
回复
要不你可以Pos一下时间与日期中间的那个分隔符(空格)
然后再判断时间是多少位!

================================================================
     ◆◆◆ CSDN查询助手,查询方便快捷◆◆◆

下载地址:
 http://CoolSlob.ifood1.com/Download/CSDNFinder.exe
 http://CoolSlob.8u8.com/Download/Tools/CSDNFinder.Slob[更名为.exe即可]
michael_king 2002-09-24
  • 打赏
  • 举报
回复
时间不一定时8位的我用了新的
NMDayTime1:=TNMDayTime.Create(self);
NMDayTime1.Host:='202.109.114.209';
NMDayTime1.Port:=13;
Label1.Caption:=NMDayTime1.DayTimeStr;
i:=pos(' ',Label1.caption);
str:=copy(Label1.Caption,0,i-1);
DecodeTime(StrToTime(str),CurrentTime.wHour,CurrentTime.wMinute,
CurrentTime.wSecond,CurrentTime.wMilliseconds);
str:=copy(Label1.Caption,i+1,Length(Label1.Caption)-8);
DecodeDate(StrToDate(trim(str)),CurrentTime.wYear,CurrentTime.wMonth,
CurrentTime.wDay);
SetLocaltime(currentTime);
日总是我哥 2002-09-24
  • 打赏
  • 举报
回复
uses StrUtils;

================================================================
     ◆◆◆ CSDN查询助手,查询方便快捷◆◆◆

下载地址:
 http://CoolSlob.ifood1.com/Download/CSDNFinder.exe
 http://CoolSlob.8u8.com/Download/Tools/CSDNFinder.Slob[更名为.exe即可]
日总是我哥 2002-09-24
  • 打赏
  • 举报
回复
str :=NMDayTime1.DayTimeStr;
Str := LeftStr(str, Length(Str) - 1);
str := RightStr(Str, Length(Str) - 8) + ' ' + LeftStr(str, 8);
DateTimeToSystemTime(StrToDateTime(Str), CurrentTime);

---以上代码在Delphi6.0下测试通过!!

================================================================
     ◆◆◆ CSDN查询助手,查询方便快捷◆◆◆

下载地址:
 http://CoolSlob.ifood1.com/Download/CSDNFinder.exe
 http://CoolSlob.8u8.com/Download/Tools/CSDNFinder.Slob[更名为.exe即可]
findcsdn 2002-09-24
  • 打赏
  • 举报
回复
这样已经很不错了。

5,386

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧