VB.net 獲取網路時間
一、首先建立正則表示式
''' <summary> ''' 正則表示式(ByVal 被檢字元, 檢索規則 strng) ''' </summary> ''' <param name="patrn">被檢字元</param> ''' <param name="strng">檢索規則</param> ''' <returns>檢索到的位置</returns> ''' <remarks></remarks> Public Function RegExp(ByVal patrn, ByVal strng) Dim regEx, Match, Matches, RetStr ' 建立變數。 RetStr = Nothing regEx = New VBScript_RegExp_55.RegExp ' 建立正則表示式。 regEx.Pattern = patrn ' 設定模式。 regEx.IgnoreCase = True ' 設定是否區分大小寫。 regEx.Global = True ' 設定全域性替換。 Matches = regEx.Execute(strng) ' 執行搜尋。 For Each Match In Matches ' 遍歷 Matches 集合。 RetStr = Match.Value Next Return RetStr End Function
二、建立一個獲取網頁原始碼的函式
''' <summary> ''' 獲得網頁資訊(網址 As String) As String ''' </summary> ''' <param name="strURL">網址</param> ''' <returns>獲得網頁資訊</returns> ''' <remarks></remarks> Public Function GetWebText(strURL As String) As String On Error Resume Next Dim url As String = strURL Dim httpReq As System.Net.HttpWebRequest httpReq.ServicePoint.ConnectionLimit = 255 Dim httpResp As System.Net.HttpWebResponse Dim httpURL As New System.Uri(url) httpReq = CType(Net.HttpWebRequest.Create(httpURL), Net.HttpWebRequest) httpReq.Method = "GET" httpResp = CType(httpReq.GetResponse(), Net.HttpWebResponse) httpReq.KeepAlive = False ' 獲取或設定一個值,該值指示是否與Internet資源建立持久連線。 Dim reader As IO.StreamReader = New IO.StreamReader(httpResp.GetResponseStream, System.Text.Encoding.GetEncoding("GB2312")) '用GB2312字元 Dim respHTML As String = reader.ReadToEnd() 'respHTML就是網頁原始碼 Dim myip As String = "" Dim myPort = "" httpResp.Close() If respHTML <> "" Then url = "" myip = "" myPort = "" End If Return respHTML End Function
三、建立獲取網路時間的函式
'獲得網路時間 ''' <summary> ''' 網路時間() ''' </summary> ''' <param name="Style">定義時間格式</param> ''' <returns>網路時間</returns> ''' <remarks></remarks> Function GetWebTime(Optional Style As Microsoft.VisualBasic.DateFormat = Nothing) As String Dim WebText = GetWebText("http://open.baidu.com/special/time/")'從百度的北京時間獲取頁面原始碼 Dim regexp As New RegularExpressions Dim WebTimes As String = RegExp("[0-9]{13}", WebText)'獲取原始碼中時間資訊 Dim WebTime As Date = #1/1/1970 8:00:00 AM#'定義初始時間 WebTime = DateAdd(DateInterval.Second, WebTimes / 1000, WebTime)'換算成現在的時間 If Style = Nothing Then'根據時間格式引數返回不同格式的時間資訊 Return WebTime Else Return Format(WebTime, Style) End If End Function
相關推薦
VB.net 獲取網路時間
一、首先建立正則表示式 ''' <summary> ''' 正則表示式(ByVal 被檢字元, 檢索規則 strng) ''' </summary>
C#/VB.NET 獲取電腦屬性(硬盤ID、硬盤容量、Cpu序列號、MAC地址、系統類型)
mic class network pcm .cn bbb alt OS -h 原文:C#/VB.NET 獲取電腦屬性(硬盤ID、硬盤容量、Cpu序列號、MAC地址、系統類型)在開發過程中,經常需要獲取電腦的一些屬性,如獲取硬盤ID/CPU序列號/MAC地址作為來加密字符串
VB.NET 檢查 網路連線
Private Declare Function InternetCheckConnection Lib "wininet.dll" Alias "InternetCheckConnectionA" (ByVal&nbs
【QT designer+ VS2013 】獲取網路時間
使用qt函式獲取網路時間 現在Qt Project Setting中的Qt Modules勾選NetWork,再匯入標頭檔案我也忘了叫什麼了 1 QStringList net_time; 2 QTcpSocket *socket = new QTcpSocket();
ESP8266用AT指令獲取網路時間
用到的指令介紹 AT+CWMODE 配置wifi模式 AT+CWJAP 連線AP AT+CIPSTART 建立TCP連線 AT+CIPSEND 透傳發送資料 具體過程 先配置WiFi,esp8266連上路由器 AT+CWMODE=3 AT+CW
獲取網路時間、獲取特定時區時間、時間同步GMT UTC
<div class="markdown_views"><p><strong>方法一:</strong></p> SimpleDateFormat dff = new SimpleDateFormat("yyyy-MM
vb.net 獲取程式執行中的路徑問題
// 獲取程式的基目錄。 System.AppDomain.CurrentDomain.BaseDirectory // 獲取模組的完整路徑。 System.Diagnostics.Process.GetCurrentProcess().MainModule.FileN
獲取網路時間並重新整理本地時間(原始碼2)
所以網上又找了一份程式碼,使用的是123埠,雖然沒有測試成功,這裡也做下記錄,估計是本機環境問題,過兩天再進行測試一下。 // getNTPTime.cpp : 定義控制檯應用程式的入口點。 // #include "stdafx.h" using namespac
C# 實現獲取網路時間
C# Winform獲取網路時間,同時顯示本地時間,支援毫秒顯示 直接上圖 工具下載 程式碼 using System; using System.Collections.Generic; using System.ComponentModel; using
C#獲取網路時間
using System; using System.Collections.Generic; using System.Text; using System.Net; namespace KISPDA { public class GetNetDateTime
獲取網路時間(國家標準時間)
我們在開發中,很多應用需要讀取網路時間來作為一個時間的標準,對業務邏輯進行相對可靠的校驗。 下面是Java中(Android一樣)讀取網路時間的程式碼: package com.test; import java.io.IOException; imp
vb.net 獲取程序列表
這個方法肯定不是最好的,查到的資料還有使用程序快照的,但是不知道為什麼vs中不能使用程序的結構體PROCESSENTRY32 Public Declare Function CreateToolhelpSnapshot Lib "kernel32" Alias "Creat
VB.NET函式——日期時間函式
<一> 獲取/設定目前日期時間函式 (1)Now ():返回系統目前的日期和時間。如:2007-3-29 早上10:38:22 (2)Today ():返回或設定系統目前的日期。 (3)TimeOfDay ():返回或設定系統目前的時間。 (4)Data
移遠M26 GSM實時獲取網路時間
移遠M26 GSM實時獲取網路時間 1.啟用同步網路時間, 開啟同步網路時間功能 AT+QNITZ=1,響應OK 2.獲取最近一次的網路同步時間 AT+QLTS,響應+QLTS: <time>,<ds> 例: +
vb.net 獲取程式執行中的路徑
// 獲取程式的基目錄。 System.AppDomain.CurrentDomain.BaseDirectory // 獲取模組的完整路徑。 System.Diagnostics.Process.GetCurrentProcess().MainModule.FileNam
獲取網路時間(國家標準時間-北京時間為準)
獲取網路時間,有些網站有偏差,提供幾個比較靠譜的網站: /** * 讀取網路時間 * */ public class NetworkTime {public static void main(String[] args) { String webUrl
徹底解決VB.NET獲取網頁原始碼的問題
在解決這個問題之前,我一直很苦惱。在網上到處搜尋,都找不到相應的解決辦法。網上,雖然有提及完全相同的問題的帖子,但是答案最後往往沒有得到發帖人的肯定,或者帖子就此die在論壇中。為了解決我設計網路爬蟲程式所不可迴避的獲取網頁編碼的問題,我克服重重困難,在MSDN的一個帖子中
使用vb.net 獲取資料夾下選中檔案的檔名稱
1. 前言 今天在配置cppunit的附加依賴項的時候, 需要輸入相應的附加依賴項的檔名, 這個很費勁, 我們又不想自己手工一個個的copy, 就希望能夠找到一種方法可以直接獲取到我們的檔名 2. 處理思路 我們這裡想到了vb.net, 利用他的拖拽功
獲取網路時間(即獲取網路時間同步伺服器的時間)
要獲取準確的時間,用於校時或其他操作,可以通過獲取時間同步伺服器的資訊來實現。下面介紹幾個常用的時間同步伺服器的域名及IP地址: 域名 IP地址 time-a.nist.gov 129.6.15.28 time-b.nist.gov 129.6.15.29 time
Unity獲取網路時間
using System.Collections; using System.Collections.Generic; using UnityEngine; public class IntTime : MonoBehaviour { private int ye