ホーム › Globalization › GetTimeFormatEx
GetTimeFormatEx
関数ロケール名を指定して時刻を文字列へ整形する。
シグネチャ
// KERNEL32.dll
#include <windows.h>
INT GetTimeFormatEx(
LPCWSTR lpLocaleName, // optional
TIME_FORMAT_FLAGS dwFlags,
const SYSTEMTIME* lpTime, // optional
LPCWSTR lpFormat, // optional
LPWSTR lpTimeStr, // optional
INT cchTime
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| lpLocaleName | LPCWSTR | inoptional |
| dwFlags | TIME_FORMAT_FLAGS | in |
| lpTime | SYSTEMTIME* | inoptional |
| lpFormat | LPCWSTR | inoptional |
| lpTimeStr | LPWSTR | outoptional |
| cchTime | INT | in |
戻り値の型: INT
各言語での呼び出し定義
// KERNEL32.dll
#include <windows.h>
INT GetTimeFormatEx(
LPCWSTR lpLocaleName, // optional
TIME_FORMAT_FLAGS dwFlags,
const SYSTEMTIME* lpTime, // optional
LPCWSTR lpFormat, // optional
LPWSTR lpTimeStr, // optional
INT cchTime
);[DllImport("KERNEL32.dll", SetLastError = true, ExactSpelling = true)]
static extern int GetTimeFormatEx(
[MarshalAs(UnmanagedType.LPWStr)] string lpLocaleName, // LPCWSTR optional
uint dwFlags, // TIME_FORMAT_FLAGS
IntPtr lpTime, // SYSTEMTIME* optional
[MarshalAs(UnmanagedType.LPWStr)] string lpFormat, // LPCWSTR optional
[MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder lpTimeStr, // LPWSTR optional, out
int cchTime // INT
);<DllImport("KERNEL32.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function GetTimeFormatEx(
<MarshalAs(UnmanagedType.LPWStr)> lpLocaleName As String, ' LPCWSTR optional
dwFlags As UInteger, ' TIME_FORMAT_FLAGS
lpTime As IntPtr, ' SYSTEMTIME* optional
<MarshalAs(UnmanagedType.LPWStr)> lpFormat As String, ' LPCWSTR optional
<MarshalAs(UnmanagedType.LPWStr)> lpTimeStr As System.Text.StringBuilder, ' LPWSTR optional, out
cchTime As Integer ' INT
) As Integer
End Function' lpLocaleName : LPCWSTR optional
' dwFlags : TIME_FORMAT_FLAGS
' lpTime : SYSTEMTIME* optional
' lpFormat : LPCWSTR optional
' lpTimeStr : LPWSTR optional, out
' cchTime : INT
Declare PtrSafe Function GetTimeFormatEx Lib "kernel32" ( _
ByVal lpLocaleName As LongPtr, _
ByVal dwFlags As Long, _
ByVal lpTime As LongPtr, _
ByVal lpFormat As LongPtr, _
ByVal lpTimeStr As LongPtr, _
ByVal cchTime As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
GetTimeFormatEx = ctypes.windll.kernel32.GetTimeFormatEx
GetTimeFormatEx.restype = ctypes.c_int
GetTimeFormatEx.argtypes = [
wintypes.LPCWSTR, # lpLocaleName : LPCWSTR optional
wintypes.DWORD, # dwFlags : TIME_FORMAT_FLAGS
ctypes.c_void_p, # lpTime : SYSTEMTIME* optional
wintypes.LPCWSTR, # lpFormat : LPCWSTR optional
wintypes.LPWSTR, # lpTimeStr : LPWSTR optional, out
ctypes.c_int, # cchTime : INT
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('KERNEL32.dll')
GetTimeFormatEx = Fiddle::Function.new(
lib['GetTimeFormatEx'],
[
Fiddle::TYPE_VOIDP, # lpLocaleName : LPCWSTR optional
-Fiddle::TYPE_INT, # dwFlags : TIME_FORMAT_FLAGS
Fiddle::TYPE_VOIDP, # lpTime : SYSTEMTIME* optional
Fiddle::TYPE_VOIDP, # lpFormat : LPCWSTR optional
Fiddle::TYPE_VOIDP, # lpTimeStr : LPWSTR optional, out
Fiddle::TYPE_INT, # cchTime : INT
],
Fiddle::TYPE_INT)#[link(name = "kernel32")]
extern "system" {
fn GetTimeFormatEx(
lpLocaleName: *const u16, // LPCWSTR optional
dwFlags: u32, // TIME_FORMAT_FLAGS
lpTime: *const SYSTEMTIME, // SYSTEMTIME* optional
lpFormat: *const u16, // LPCWSTR optional
lpTimeStr: *mut u16, // LPWSTR optional, out
cchTime: i32 // INT
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("KERNEL32.dll", SetLastError = true)]
public static extern int GetTimeFormatEx([MarshalAs(UnmanagedType.LPWStr)] string lpLocaleName, uint dwFlags, IntPtr lpTime, [MarshalAs(UnmanagedType.LPWStr)] string lpFormat, [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder lpTimeStr, int cchTime);
"@
$api = Add-Type -MemberDefinition $sig -Name 'KERNEL32_GetTimeFormatEx' -Namespace Win32 -PassThru
# $api::GetTimeFormatEx(lpLocaleName, dwFlags, lpTime, lpFormat, lpTimeStr, cchTime)#uselib "KERNEL32.dll"
#func global GetTimeFormatEx "GetTimeFormatEx" sptr, sptr, sptr, sptr, sptr, sptr
; GetTimeFormatEx lpLocaleName, dwFlags, varptr(lpTime), lpFormat, varptr(lpTimeStr), cchTime ; 戻り値は stat
; lpLocaleName : LPCWSTR optional -> "sptr"
; dwFlags : TIME_FORMAT_FLAGS -> "sptr"
; lpTime : SYSTEMTIME* optional -> "sptr"
; lpFormat : LPCWSTR optional -> "sptr"
; lpTimeStr : LPWSTR optional, out -> "sptr"
; cchTime : INT -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "KERNEL32.dll" #cfunc global GetTimeFormatEx "GetTimeFormatEx" wstr, int, var, wstr, var, int ; res = GetTimeFormatEx(lpLocaleName, dwFlags, lpTime, lpFormat, lpTimeStr, cchTime) ; lpLocaleName : LPCWSTR optional -> "wstr" ; dwFlags : TIME_FORMAT_FLAGS -> "int" ; lpTime : SYSTEMTIME* optional -> "var" ; lpFormat : LPCWSTR optional -> "wstr" ; lpTimeStr : LPWSTR optional, out -> "var" ; cchTime : INT -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "KERNEL32.dll" #cfunc global GetTimeFormatEx "GetTimeFormatEx" wstr, int, sptr, wstr, sptr, int ; res = GetTimeFormatEx(lpLocaleName, dwFlags, varptr(lpTime), lpFormat, varptr(lpTimeStr), cchTime) ; lpLocaleName : LPCWSTR optional -> "wstr" ; dwFlags : TIME_FORMAT_FLAGS -> "int" ; lpTime : SYSTEMTIME* optional -> "sptr" ; lpFormat : LPCWSTR optional -> "wstr" ; lpTimeStr : LPWSTR optional, out -> "sptr" ; cchTime : INT -> "int" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; INT GetTimeFormatEx(LPCWSTR lpLocaleName, TIME_FORMAT_FLAGS dwFlags, SYSTEMTIME* lpTime, LPCWSTR lpFormat, LPWSTR lpTimeStr, INT cchTime) #uselib "KERNEL32.dll" #cfunc global GetTimeFormatEx "GetTimeFormatEx" wstr, int, var, wstr, var, int ; res = GetTimeFormatEx(lpLocaleName, dwFlags, lpTime, lpFormat, lpTimeStr, cchTime) ; lpLocaleName : LPCWSTR optional -> "wstr" ; dwFlags : TIME_FORMAT_FLAGS -> "int" ; lpTime : SYSTEMTIME* optional -> "var" ; lpFormat : LPCWSTR optional -> "wstr" ; lpTimeStr : LPWSTR optional, out -> "var" ; cchTime : INT -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; INT GetTimeFormatEx(LPCWSTR lpLocaleName, TIME_FORMAT_FLAGS dwFlags, SYSTEMTIME* lpTime, LPCWSTR lpFormat, LPWSTR lpTimeStr, INT cchTime) #uselib "KERNEL32.dll" #cfunc global GetTimeFormatEx "GetTimeFormatEx" wstr, int, intptr, wstr, intptr, int ; res = GetTimeFormatEx(lpLocaleName, dwFlags, varptr(lpTime), lpFormat, varptr(lpTimeStr), cchTime) ; lpLocaleName : LPCWSTR optional -> "wstr" ; dwFlags : TIME_FORMAT_FLAGS -> "int" ; lpTime : SYSTEMTIME* optional -> "intptr" ; lpFormat : LPCWSTR optional -> "wstr" ; lpTimeStr : LPWSTR optional, out -> "intptr" ; cchTime : INT -> "int" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
procGetTimeFormatEx = kernel32.NewProc("GetTimeFormatEx")
)
// lpLocaleName (LPCWSTR optional), dwFlags (TIME_FORMAT_FLAGS), lpTime (SYSTEMTIME* optional), lpFormat (LPCWSTR optional), lpTimeStr (LPWSTR optional, out), cchTime (INT)
r1, _, err := procGetTimeFormatEx.Call(
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(lpLocaleName))),
uintptr(dwFlags),
uintptr(lpTime),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(lpFormat))),
uintptr(lpTimeStr),
uintptr(cchTime),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // INTfunction GetTimeFormatEx(
lpLocaleName: PWideChar; // LPCWSTR optional
dwFlags: DWORD; // TIME_FORMAT_FLAGS
lpTime: Pointer; // SYSTEMTIME* optional
lpFormat: PWideChar; // LPCWSTR optional
lpTimeStr: PWideChar; // LPWSTR optional, out
cchTime: Integer // INT
): Integer; stdcall;
external 'KERNEL32.dll' name 'GetTimeFormatEx';result := DllCall("KERNEL32\GetTimeFormatEx"
, "WStr", lpLocaleName ; LPCWSTR optional
, "UInt", dwFlags ; TIME_FORMAT_FLAGS
, "Ptr", lpTime ; SYSTEMTIME* optional
, "WStr", lpFormat ; LPCWSTR optional
, "Ptr", lpTimeStr ; LPWSTR optional, out
, "Int", cchTime ; INT
, "Int") ; return: INT●GetTimeFormatEx(lpLocaleName, dwFlags, lpTime, lpFormat, lpTimeStr, cchTime) = DLL("KERNEL32.dll", "int GetTimeFormatEx(char*, dword, void*, char*, char*, int)")
# 呼び出し: GetTimeFormatEx(lpLocaleName, dwFlags, lpTime, lpFormat, lpTimeStr, cchTime)
# lpLocaleName : LPCWSTR optional -> "char*"
# dwFlags : TIME_FORMAT_FLAGS -> "dword"
# lpTime : SYSTEMTIME* optional -> "void*"
# lpFormat : LPCWSTR optional -> "char*"
# lpTimeStr : LPWSTR optional, out -> "char*"
# cchTime : INT -> "int"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。