delphi 获取北京时间(使用XMLHTTP获取百度的时间,WebBrowser获取www.timedate.cn的时间)
方法一:
uses
ComObj, DateUtils; function GetInternetTime: string;
var
XmlHttp: OleVariant;
datetxt: string;
DateLst: TStringList;
mon: string;
timeGMT, GetNetTime: TDateTime;
s: string;
begin
XmlHttp := CreateOleObject('Microsoft.XMLHTTP');
XmlHttp.Open('GET', 'http://open.baidu.com/special/time/', False);
XmlHttp.Send; datetxt := XmlHttp.GetResponseHeader('Date');
datetxt := Copy(datetxt, Pos(',', datetxt) + , );
datetxt := StringReplace(datetxt, 'GMT', '', []);
datetxt := Trim(datetxt);
if datetxt = '' then Exit;
DateLst := TStringList.Create;
while Pos(' ', datetxt) > do
begin
DateLst.Add(Copy(datetxt, , Pos(' ', datetxt) - ));
datetxt := Copy(datetxt, Pos(' ', datetxt) + , );
end;
DateLst.Add(datetxt);
if DateLst[] = 'Jan' then
mon := ''
else if DateLst[] = 'Feb' then
mon := ''
else if DateLst[] = 'Mar' then
mon := ''
else if DateLst[] = 'Apr' then
mon := ''
else if DateLst[] = 'Mar' then
mon := ''
else if DateLst[] = 'Jun' then
mon := ''
else if DateLst[] = 'Jul' then
mon := ''
else if DateLst[] = 'Aug' then
mon := ''
else if DateLst[] = 'Sep' then
mon := ''
else if DateLst[] = 'Oct' then
mon := ''
else if DateLst[] = 'Nov' then
mon := ''
else if DateLst[] = 'Dec' then
mon := '';
s := DateLst[] + '-' + mon + '-' + DateLst[] + ' ' + DateLst[];
//标准时间
// ShowMessage(s);
// '/' or '-'
timeGMT := StrToDateTime(DateLst[] + '-' + mon + '-' + DateLst[] + ' ' + DateLst[]);
//转换时区
GetNetTime := IncHour(TimeGMT, );
// ShowMessage(FormatDateTime('yyyy年mm月dd日 HH:NN:SS', GetNetTime));
FreeAndNil(DateLst);
Result:= FormatDateTime('yyyy年mm月dd日 HH:NN:SS', GetNetTime);
end;
方法二:
procedure TForm1.FormCreate(Sender: TObject);
begin
WebBrowser.Navigate('http://www.timedate.cn/worldclock/ti.asp');
tmr1.Enabled := True;
end; procedure TForm1.WebBrowserStatusTextChange(Sender: TObject;
const Text: WideString);
var
strText: string;
begin
strText := Text;
if strText = '完成' Then
begin
Caption := WebBrowser.OleObject.Document.Body.Innertext;
tmr1.Enabled := True
end;
end; procedure TForm1.tmr1Timer(Sender: TObject);
begin
tmr1.Enabled := False;
WebBrowser.Refresh
end;
http://blog.csdn.net/yanjiaye520/article/details/7887463
delphi 获取北京时间(使用XMLHTTP获取百度的时间,WebBrowser获取www.timedate.cn的时间)的更多相关文章
- Delphi 获取北京时间(通过百度和timedate网站)
方法一: uses ComObj, DateUtils; function GetInternetTime: string; var XmlHttp: OleVariant; datetxt: str ...
- C#获取北京时间与设置系统时间
获取北京时间 public static DateTime GetBeijingTime() { DateTime dt; // 返回国际标准时间 // 只使用 timeServers 的 IP 地址 ...
- atitit.获取北京时间CST 功能api总结 O7
atitit.获取北京时间CST 功能api总结 O7 1. 获取cst时间(北京时间)两布:1.抓取url timtstamp >>format 到cst 1 2. 设置本机时间 se ...
- 基于百度定位及天气获取的DEMO
demo基于百度定位APIv4.0版.新浪天气(不用查询城市代码). 需求: 1.button实现触发定位监听和天气捕获 2.两个textview 分别显示详细地址.天气. 界面很简陋,侧重功能实现. ...
- IOS中使用百度地图定位后获取城市坐标,城市名称,城市编号信息
IOS中使用百度地图定位后获取城市坐标,城市名称,城市编号信息 /**当获取到定位的坐标后,回调函数*/ - (void)didUpdateBMKUserLocation:(BMKUserLocati ...
- 百度地图JavaScript API获取用户当前经纬度和详细地理位置,反之通过详细地理位置获取当前经纬度
前言: 前端时间刚好使用了百度地图的js api定位获取用户当前经纬度并获取当前详细位置和通过当前用户详细地理位置换取用户当前经纬度坐标的功能,为了方便下次找起来方便一些自己在这里记录一下,希望也能够 ...
- 用户Ip地址和百度地图api接口获取用户地理位置(经纬度坐标,城市)
<?php //获取用户ip(外网ip 服务器上可以获取用户外网Ip 本机ip地址只能获取127.0.0.1) function getip(){ if(!empty($_SERVE ...
- 利用百度地图API,获取经纬度坐标
利用百度地图API,获取经纬度坐标 代码很简单,但在网上没找到现成的获取地图经纬度的页面. 就是想,给当前页面传递一个经纬度,自动定位到此经纬度.然后可以重新选择,选择完返回经纬度. 效果如下: 源代 ...
- 利用百度翻译API,获取翻译结果
利用百度翻译API,获取翻译结果 translate.py #!/usr/bin/python #-*- coding:utf-8 -*- import sys reload(sys) sys.set ...
随机推荐
- BZOJ 1458 士兵占领
http://www.lydsy.com/JudgeOnline/problem.php?id=1458 题意:n x m的棋盘,k个位置不能放,每行和每列都有要求至少的士兵,求能否有最少的满足条件的 ...
- Keil中如何消除UNCALLED SEGMENT,IGNORED FOR OVERLAY PROCESS警告
在Keil C中,如果没有显式调用到定义过的函数,就会出现这样的的警告.当出现这样的警告时,可以不用管,因为不影响其它部分.但是,我们知道,即使没有调用这个函数,Keil仍然把它编译连接进整个程序,不 ...
- 对Qt for Android的评价(很全面,基本已经没有问题了,网易战网客户端就是Qt quick写的),可以重用QT积累20年的RTL是好事,QML效率是HTML5的5倍
现在Qt不要光看跨平台了,Qt也有能力和原生应用进行较量的.可以直接去Qt官网查看他和那些厂商合作.关于和Java的比较,框架和Java进行比较似乎不且实际.如果是C++和Java比较,网上有很多文章 ...
- Jedis超时时间设置梳理
JedisConnectionException: Unexpected end of stream #932 Repeatable exception and for the life of me, ...
- SHELL中的特殊变量和结构
SHELL中的特殊变量和结构 表格 B-1. 特殊的shell变量 变量 含义 $0 脚本名字 $1 位置参数 #1 $2 - $9 位置参数 #2 - #9 ${10} 位置参数 #10 $# 位置 ...
- 【转】飞凌嵌入式(Forlinx)TE/OK6410内核编译:“make: arm-none-linux-gnueabi-gcc:命令未找到”
原文网址:http://www.xuebuyuan.com/1104711.html Ubuntu10.04下编译飞凌嵌入式(Forlinx)TE/OK6410开发板提供的内核2.6.36 本以为按照 ...
- 布局文件提示错误“No orientation specified, and the default is horizontal. This is a common so...”
完整的错误提示信息为:No orientation specified, and the default is horizontal. This is a common source of bugs ...
- [Redux] Generating Containers with connect() from React Redux (FooterLink)
Code to be refactored: class FilterLink extends Component { componentDidMount() { const { store } = ...
- 从一段代码看fork()函数及其引发的竞争
首先来看一段从<UNIX环境高级编程>中摘录的一段很有意思的代码.借此我们再来谈谈fork()函数的一些问题. #include "apue.h" static voi ...
- 求斐波那契数列的第n项
问题描述:斐波那契数列是这样的一个数列,1,1,2,3,5,8,..,即前两项都是1,后面每一项都是其前面两项的和. 现在要你求出该数列的第n项. 分析:该问题是一个经典的数列问题,相信大家在很多语言 ...