HTTP形式・SYSTEMTIME形式時間の相互変換          <TOP>


インターネット形式とDate形式の時間を相互に変換します。

InternetTimeToSystemTime インターネット(HTTP)形式の時間をSYSTEMTIME形式時間に変換
InternetTimeFromSystemTime SYSTEMTIME形式の時間をインターネット(HTTP)形式時間に変換
 

 

'================================================================
'= HTTP形式・SYSTEMTIME形式時間の相互変換
'=    (InternetTimeToSystemTime.bas)
'================================================================
#include "Windows.bi"

Type SYSTEMTIME
    wYear         As Integer
    wMonth        As Integer
    wDayOfWeek    As Integer
    wDay          As Integer
    wHour         As Integer
    wMinute       As Integer
    wSecond       As Integer
    wMilliseconds As Integer
End Type

' インターネット(HTTP)形式の時間をSYSTEMTIME形式時間に変換
Declare Function Api_InternetTimeToSystemTime& Lib "wininet" Alias "InternetTimeToSystemTimeA" (ByVal lpszTime$, ByRef pst As SYSTEMTIME, ByVal dwReserved&)

' SYSTEMTIME形式の時間をインターネット(HTTP)形式時間に変換
Declare Function Api_InternetTimeFromSystemTime& Lib "wininet" Alias "InternetTimeFromSystemTimeA" (ByRef pst As SYSTEMTIME, ByVal dwRFC&, ByVal lpszTime$, ByVal cbTime&)

#define INTERNET_RFC1123_FORMAT 0       'RFC1123形式
#define INTERNET_RFC1123_BUFSIZE 30     '

Var Shared Text(5) As Object
Var Shared Button(1) As Object
Var Shared Timer1 As Object

For i = 0 To 5
    If i < 2 Then
        Button(i).Attach GetDlgItem("Button" & Trim$(Str$(i + 1))) : Button(i).SetFontSize 14
    End If
    Text(i).Attach GetDlgItem("Text" & Trim$(Str$(i + 1))) : Text(i).SetFontSize 14
Next
Timer1.Attach GetDlgItem("Timer1")

'================================================================
'=
'================================================================
Declare Sub MainForm_Start edecl ()
Sub MainForm_Start()
    Text(0).SetWindowtext Today$ & " " & Time$

    Timer1.SetInterval 10
    Timer1.Enable -1
End Sub

'================================================================
'=
'================================================================
Declare Sub Timer1_Timer edecl ()
Sub Timer1_Timer()
    Text(0).SetWindowtext Today$ & " " & Time$
End Sub

'================================================================
'= HTTP --> DATE
'================================================================
Declare Sub Button1_on edecl ()
Sub Button1_on()
    Var dt As String
    Var st As SYSTEMTIME
    Var strTime As String

    dt = Text(0).GetWindowText

    st.wYear = Val(Left$(dt, 4))
    st.wMonth = Val(Mid$(dt, 6, 2))
    st.wDay = Val(Mid$(dt, 9, 2))
    st.wHour = Val(Mid$(dt, 12, 2))
    st.wMinute = Val(Mid$(dt, 15, 2))
    st.wSecond = Val(Right$(dt, 2))

    strTime = String$(INTERNET_RFC1123_BUFSIZE + 1, 0)

    Ret = Api_InternetTimeFromSystemTime(st, INTERNET_RFC1123_FORMAT, strTime, Len(strTime))

    Text(1).SetWindowText strTime
    Text(2).SetWindowText ""
End Sub

'================================================================
'= DATE --> HTTP
'================================================================
Declare Sub Button2_on edecl ()
Sub Button2_on()
    Var strTime As String
    Var st As SYSTEMTIME
    Var Ret As Long

    strTime =Text(1).GetWindowText

    Ret = Api_InternetTimeToSystemTime(strTime, st, 0)

    Text(2).SetWindowText Trim$(Str$(st.wYear)) & "/" & Trim$(Str$(st.wMonth)) & "/" & Trim$(Str$(st.wDay)) & " " & Trim$(Str$(st.wHour)) & ":" & Trim$(Str$(st.wMinute)) & ":" & Trim$(Str$(st.wSecond))
End Sub

'================================================================
'=
'================================================================
While 1
    WaitEvent
Wend
Stop
End