日付・時刻の書式を取得          <TOP>


日付表示・時刻表示の書式を取得します。

GetDateFormat 日付表示の書式を取得

GetTimeFormat 時刻表示の書式を取得

 

地域と言語のオプションで設定された書式(フォーマット)に準じます。
例では、today$で取得した日付・時刻をシステムタイム構造体に代入し地域オプションで設定したフォーマットで出力しています。

 

 

 

 

 

'================================================================
'= 日付・時刻の書式を取得
'=    (GetDateFormat.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

' 日付表示の書式を取得
Declare Function Api_GetDateFormat& Lib "Kernel32" Alias "GetDateFormatA" (ByVal Locale&, ByVal dwFlags&, lpDate As SYSTEMTIME, ByVal lpFormat$, ByVal lpDateStr$, ByVal cchDate&)

' 時刻をフォーマットし、指定された地域に対応する時刻文字列を作成
Declare Function Api_GetTimeFormat& Lib "kernel32" Alias "GetTimeFormatA" (ByVal Locale&, ByVal dwFlags&, lpTime As SYSTEMTIME, ByVal lpFormat As Any, ByVal lpTimeStr$, ByVal cchTime&)

Var Shared Text1 As Object
Var Shared Text2 As Object
Var Shared Timer1 As Object

Text1.Attach GetDlgItem("Text1") : Text1.SetFontSize 20
Text2.Attach GetDlgItem("Text2") : Text2.SetFontSize 20
Timer1.Attach GetDlgItem("Timer1")

'================================================================
'=
'================================================================
Declare Sub MainForm_Start edecl ()
Sub MainForm_Start()
    Timer1.SetInterval 100
    Timer1.Enable -1
End Sub

'================================================================
'=
'================================================================
Declare Sub Timer1_Timer edecl ()
Sub Timer1_Timer()
    Var Buffer As String
    Var st As SYSTEMTIME
    Var Ret As Long

    st.wDay = Val(Right$(Today$, 2))
    st.wMonth = Val(Mid$(Today$, 6, 2))
    st.wYear = Val(Left$(Today$, 4))

    st.wHour = Val(Left$(Time$, 2))
    st.wMinute = Val(Mid$(Time$, 4, 2))
    st.wSecond = Val(Right$(Time$, 2))

    Buffer = String$(255, 0)
    Ret = Api_GetDateFormat(ByVal 0, 0, st, ByVal 0, Buffer, Len(Buffer))
    Buffer = Left$(Buffer, InStr(1, Buffer, Chr$(0)) - 1)
    Text1.SetWindowText Buffer

    Buffer = String$(255, 0)
    Ret = Api_GetTimeFormat(ByVal 0, 0, st, ByVal 0, Buffer, Len(Buffer))
    Buffer = Left$(Buffer, InStr(1, Buffer, Chr$(0)) - 1)
    Text2.SetWindowText Buffer

End Sub

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