Win32 API 日本語リファレンス
ホームSystem.Time › SystemTimeToTzSpecificLocalTimeEx

SystemTimeToTzSpecificLocalTimeEx

関数
動的タイムゾーンでUTC時刻をローカル時刻に変換する。
DLLKERNEL32.dll呼出規約winapiSetLastErrorあり対応OSWindows 7 以降

シグネチャ

// KERNEL32.dll
#include <windows.h>

BOOL SystemTimeToTzSpecificLocalTimeEx(
    const DYNAMIC_TIME_ZONE_INFORMATION* lpTimeZoneInformation,   // optional
    const SYSTEMTIME* lpUniversalTime,
    SYSTEMTIME* lpLocalTime
);

パラメーター

名前方向説明
lpTimeZoneInformationDYNAMIC_TIME_ZONE_INFORMATION*inoptional変換に用いる動的タイムゾーン情報へのポインタ。NULLで現在の設定を使う。
lpUniversalTimeSYSTEMTIME*in変換元のUTC時刻を示すSYSTEMTIME構造体へのポインタ。
lpLocalTimeSYSTEMTIME*out変換後のローカル時刻を受け取るSYSTEMTIME構造体へのポインタ。

戻り値の型: BOOL

各言語での呼び出し定義

// KERNEL32.dll
#include <windows.h>

BOOL SystemTimeToTzSpecificLocalTimeEx(
    const DYNAMIC_TIME_ZONE_INFORMATION* lpTimeZoneInformation,   // optional
    const SYSTEMTIME* lpUniversalTime,
    SYSTEMTIME* lpLocalTime
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("KERNEL32.dll", SetLastError = true, ExactSpelling = true)]
static extern bool SystemTimeToTzSpecificLocalTimeEx(
    IntPtr lpTimeZoneInformation,   // DYNAMIC_TIME_ZONE_INFORMATION* optional
    IntPtr lpUniversalTime,   // SYSTEMTIME*
    IntPtr lpLocalTime   // SYSTEMTIME* out
);
<DllImport("KERNEL32.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function SystemTimeToTzSpecificLocalTimeEx(
    lpTimeZoneInformation As IntPtr,   ' DYNAMIC_TIME_ZONE_INFORMATION* optional
    lpUniversalTime As IntPtr,   ' SYSTEMTIME*
    lpLocalTime As IntPtr   ' SYSTEMTIME* out
) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function
' lpTimeZoneInformation : DYNAMIC_TIME_ZONE_INFORMATION* optional
' lpUniversalTime : SYSTEMTIME*
' lpLocalTime : SYSTEMTIME* out
Declare PtrSafe Function SystemTimeToTzSpecificLocalTimeEx Lib "kernel32" ( _
    ByVal lpTimeZoneInformation As LongPtr, _
    ByVal lpUniversalTime As LongPtr, _
    ByVal lpLocalTime As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

SystemTimeToTzSpecificLocalTimeEx = ctypes.windll.kernel32.SystemTimeToTzSpecificLocalTimeEx
SystemTimeToTzSpecificLocalTimeEx.restype = wintypes.BOOL
SystemTimeToTzSpecificLocalTimeEx.argtypes = [
    ctypes.c_void_p,  # lpTimeZoneInformation : DYNAMIC_TIME_ZONE_INFORMATION* optional
    ctypes.c_void_p,  # lpUniversalTime : SYSTEMTIME*
    ctypes.c_void_p,  # lpLocalTime : SYSTEMTIME* out
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('KERNEL32.dll')
SystemTimeToTzSpecificLocalTimeEx = Fiddle::Function.new(
  lib['SystemTimeToTzSpecificLocalTimeEx'],
  [
    Fiddle::TYPE_VOIDP,  # lpTimeZoneInformation : DYNAMIC_TIME_ZONE_INFORMATION* optional
    Fiddle::TYPE_VOIDP,  # lpUniversalTime : SYSTEMTIME*
    Fiddle::TYPE_VOIDP,  # lpLocalTime : SYSTEMTIME* out
  ],
  Fiddle::TYPE_INT)
#[link(name = "kernel32")]
extern "system" {
    fn SystemTimeToTzSpecificLocalTimeEx(
        lpTimeZoneInformation: *const DYNAMIC_TIME_ZONE_INFORMATION,  // DYNAMIC_TIME_ZONE_INFORMATION* optional
        lpUniversalTime: *const SYSTEMTIME,  // SYSTEMTIME*
        lpLocalTime: *mut SYSTEMTIME  // SYSTEMTIME* out
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("KERNEL32.dll", SetLastError = true)]
public static extern bool SystemTimeToTzSpecificLocalTimeEx(IntPtr lpTimeZoneInformation, IntPtr lpUniversalTime, IntPtr lpLocalTime);
"@
$api = Add-Type -MemberDefinition $sig -Name 'KERNEL32_SystemTimeToTzSpecificLocalTimeEx' -Namespace Win32 -PassThru
# $api::SystemTimeToTzSpecificLocalTimeEx(lpTimeZoneInformation, lpUniversalTime, lpLocalTime)
#uselib "KERNEL32.dll"
#func global SystemTimeToTzSpecificLocalTimeEx "SystemTimeToTzSpecificLocalTimeEx" sptr, sptr, sptr
; SystemTimeToTzSpecificLocalTimeEx varptr(lpTimeZoneInformation), varptr(lpUniversalTime), varptr(lpLocalTime)   ; 戻り値は stat
; lpTimeZoneInformation : DYNAMIC_TIME_ZONE_INFORMATION* optional -> "sptr"
; lpUniversalTime : SYSTEMTIME* -> "sptr"
; lpLocalTime : SYSTEMTIME* out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "KERNEL32.dll"
#cfunc global SystemTimeToTzSpecificLocalTimeEx "SystemTimeToTzSpecificLocalTimeEx" var, var, var
; res = SystemTimeToTzSpecificLocalTimeEx(lpTimeZoneInformation, lpUniversalTime, lpLocalTime)
; lpTimeZoneInformation : DYNAMIC_TIME_ZONE_INFORMATION* optional -> "var"
; lpUniversalTime : SYSTEMTIME* -> "var"
; lpLocalTime : SYSTEMTIME* out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; BOOL SystemTimeToTzSpecificLocalTimeEx(DYNAMIC_TIME_ZONE_INFORMATION* lpTimeZoneInformation, SYSTEMTIME* lpUniversalTime, SYSTEMTIME* lpLocalTime)
#uselib "KERNEL32.dll"
#cfunc global SystemTimeToTzSpecificLocalTimeEx "SystemTimeToTzSpecificLocalTimeEx" var, var, var
; res = SystemTimeToTzSpecificLocalTimeEx(lpTimeZoneInformation, lpUniversalTime, lpLocalTime)
; lpTimeZoneInformation : DYNAMIC_TIME_ZONE_INFORMATION* optional -> "var"
; lpUniversalTime : SYSTEMTIME* -> "var"
; lpLocalTime : SYSTEMTIME* out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
	procSystemTimeToTzSpecificLocalTimeEx = kernel32.NewProc("SystemTimeToTzSpecificLocalTimeEx")
)

// lpTimeZoneInformation (DYNAMIC_TIME_ZONE_INFORMATION* optional), lpUniversalTime (SYSTEMTIME*), lpLocalTime (SYSTEMTIME* out)
r1, _, err := procSystemTimeToTzSpecificLocalTimeEx.Call(
	uintptr(lpTimeZoneInformation),
	uintptr(lpUniversalTime),
	uintptr(lpLocalTime),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOL
function SystemTimeToTzSpecificLocalTimeEx(
  lpTimeZoneInformation: Pointer;   // DYNAMIC_TIME_ZONE_INFORMATION* optional
  lpUniversalTime: Pointer;   // SYSTEMTIME*
  lpLocalTime: Pointer   // SYSTEMTIME* out
): BOOL; stdcall;
  external 'KERNEL32.dll' name 'SystemTimeToTzSpecificLocalTimeEx';
result := DllCall("KERNEL32\SystemTimeToTzSpecificLocalTimeEx"
    , "Ptr", lpTimeZoneInformation   ; DYNAMIC_TIME_ZONE_INFORMATION* optional
    , "Ptr", lpUniversalTime   ; SYSTEMTIME*
    , "Ptr", lpLocalTime   ; SYSTEMTIME* out
    , "Int")   ; return: BOOL
●SystemTimeToTzSpecificLocalTimeEx(lpTimeZoneInformation, lpUniversalTime, lpLocalTime) = DLL("KERNEL32.dll", "bool SystemTimeToTzSpecificLocalTimeEx(void*, void*, void*)")
# 呼び出し: SystemTimeToTzSpecificLocalTimeEx(lpTimeZoneInformation, lpUniversalTime, lpLocalTime)
# lpTimeZoneInformation : DYNAMIC_TIME_ZONE_INFORMATION* optional -> "void*"
# lpUniversalTime : SYSTEMTIME* -> "void*"
# lpLocalTime : SYSTEMTIME* out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

extern "kernel32" fn SystemTimeToTzSpecificLocalTimeEx(
    lpTimeZoneInformation: [*c]DYNAMIC_TIME_ZONE_INFORMATION, // DYNAMIC_TIME_ZONE_INFORMATION* optional
    lpUniversalTime: [*c]SYSTEMTIME, // SYSTEMTIME*
    lpLocalTime: [*c]SYSTEMTIME // SYSTEMTIME* out
) callconv(std.os.windows.WINAPI) i32;
proc SystemTimeToTzSpecificLocalTimeEx(
    lpTimeZoneInformation: ptr DYNAMIC_TIME_ZONE_INFORMATION,  # DYNAMIC_TIME_ZONE_INFORMATION* optional
    lpUniversalTime: ptr SYSTEMTIME,  # SYSTEMTIME*
    lpLocalTime: ptr SYSTEMTIME  # SYSTEMTIME* out
): int32 {.importc: "SystemTimeToTzSpecificLocalTimeEx", stdcall, dynlib: "KERNEL32.dll".}
pragma(lib, "kernel32");
extern(Windows)
int SystemTimeToTzSpecificLocalTimeEx(
    DYNAMIC_TIME_ZONE_INFORMATION* lpTimeZoneInformation,   // DYNAMIC_TIME_ZONE_INFORMATION* optional
    SYSTEMTIME* lpUniversalTime,   // SYSTEMTIME*
    SYSTEMTIME* lpLocalTime   // SYSTEMTIME* out
);
ccall((:SystemTimeToTzSpecificLocalTimeEx, "KERNEL32.dll"), stdcall, Int32,
      (Ptr{DYNAMIC_TIME_ZONE_INFORMATION}, Ptr{SYSTEMTIME}, Ptr{SYSTEMTIME}),
      lpTimeZoneInformation, lpUniversalTime, lpLocalTime)
# lpTimeZoneInformation : DYNAMIC_TIME_ZONE_INFORMATION* optional -> Ptr{DYNAMIC_TIME_ZONE_INFORMATION}
# lpUniversalTime : SYSTEMTIME* -> Ptr{SYSTEMTIME}
# lpLocalTime : SYSTEMTIME* out -> Ptr{SYSTEMTIME}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
int32_t SystemTimeToTzSpecificLocalTimeEx(
    void* lpTimeZoneInformation,
    void* lpUniversalTime,
    void* lpLocalTime);
]]
local kernel32 = ffi.load("kernel32")
-- kernel32.SystemTimeToTzSpecificLocalTimeEx(lpTimeZoneInformation, lpUniversalTime, lpLocalTime)
-- lpTimeZoneInformation : DYNAMIC_TIME_ZONE_INFORMATION* optional
-- lpUniversalTime : SYSTEMTIME*
-- lpLocalTime : SYSTEMTIME* out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('KERNEL32.dll');
const SystemTimeToTzSpecificLocalTimeEx = lib.func('__stdcall', 'SystemTimeToTzSpecificLocalTimeEx', 'int32_t', ['void *', 'void *', 'void *']);
// SystemTimeToTzSpecificLocalTimeEx(lpTimeZoneInformation, lpUniversalTime, lpLocalTime)
// lpTimeZoneInformation : DYNAMIC_TIME_ZONE_INFORMATION* optional -> 'void *'
// lpUniversalTime : SYSTEMTIME* -> 'void *'
// lpLocalTime : SYSTEMTIME* out -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("KERNEL32.dll", {
  SystemTimeToTzSpecificLocalTimeEx: { parameters: ["pointer", "pointer", "pointer"], result: "i32" },
});
// lib.symbols.SystemTimeToTzSpecificLocalTimeEx(lpTimeZoneInformation, lpUniversalTime, lpLocalTime)
// lpTimeZoneInformation : DYNAMIC_TIME_ZONE_INFORMATION* optional -> "pointer"
// lpUniversalTime : SYSTEMTIME* -> "pointer"
// lpLocalTime : SYSTEMTIME* out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t SystemTimeToTzSpecificLocalTimeEx(
    void* lpTimeZoneInformation,
    void* lpUniversalTime,
    void* lpLocalTime);
C, "KERNEL32.dll");
// $ffi->SystemTimeToTzSpecificLocalTimeEx(lpTimeZoneInformation, lpUniversalTime, lpLocalTime);
// lpTimeZoneInformation : DYNAMIC_TIME_ZONE_INFORMATION* optional
// lpUniversalTime : SYSTEMTIME*
// lpLocalTime : SYSTEMTIME* out
// 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
// WINAPI(stdcall): x64 では呼出規約が統一されるため問題なし。x86 では __stdcall 対応のラッパが必要な場合あり。
import com.sun.jna.*;
import com.sun.jna.ptr.*;
import com.sun.jna.win32.StdCallLibrary;
import com.sun.jna.win32.W32APIOptions;

public interface Kernel32 extends StdCallLibrary {
    Kernel32 INSTANCE = Native.load("kernel32", Kernel32.class);
    boolean SystemTimeToTzSpecificLocalTimeEx(
        Pointer lpTimeZoneInformation,   // DYNAMIC_TIME_ZONE_INFORMATION* optional
        Pointer lpUniversalTime,   // SYSTEMTIME*
        Pointer lpLocalTime   // SYSTEMTIME* out
    );
}
@[Link("kernel32")]
lib LibKERNEL32
  fun SystemTimeToTzSpecificLocalTimeEx = SystemTimeToTzSpecificLocalTimeEx(
    lpTimeZoneInformation : DYNAMIC_TIME_ZONE_INFORMATION*,   # DYNAMIC_TIME_ZONE_INFORMATION* optional
    lpUniversalTime : SYSTEMTIME*,   # SYSTEMTIME*
    lpLocalTime : SYSTEMTIME*   # SYSTEMTIME* out
  ) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef SystemTimeToTzSpecificLocalTimeExNative = Int32 Function(Pointer<Void>, Pointer<Void>, Pointer<Void>);
typedef SystemTimeToTzSpecificLocalTimeExDart = int Function(Pointer<Void>, Pointer<Void>, Pointer<Void>);
final SystemTimeToTzSpecificLocalTimeEx = DynamicLibrary.open('KERNEL32.dll')
    .lookupFunction<SystemTimeToTzSpecificLocalTimeExNative, SystemTimeToTzSpecificLocalTimeExDart>('SystemTimeToTzSpecificLocalTimeEx');
// lpTimeZoneInformation : DYNAMIC_TIME_ZONE_INFORMATION* optional -> Pointer<Void>
// lpUniversalTime : SYSTEMTIME* -> Pointer<Void>
// lpLocalTime : SYSTEMTIME* out -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function SystemTimeToTzSpecificLocalTimeEx(
  lpTimeZoneInformation: Pointer;   // DYNAMIC_TIME_ZONE_INFORMATION* optional
  lpUniversalTime: Pointer;   // SYSTEMTIME*
  lpLocalTime: Pointer   // SYSTEMTIME* out
): BOOL; stdcall;
  external 'KERNEL32.dll' name 'SystemTimeToTzSpecificLocalTimeEx';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "SystemTimeToTzSpecificLocalTimeEx"
  c_SystemTimeToTzSpecificLocalTimeEx :: Ptr () -> Ptr () -> Ptr () -> IO CInt
-- lpTimeZoneInformation : DYNAMIC_TIME_ZONE_INFORMATION* optional -> Ptr ()
-- lpUniversalTime : SYSTEMTIME* -> Ptr ()
-- lpLocalTime : SYSTEMTIME* out -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let systemtimetotzspecificlocaltimeex =
  foreign "SystemTimeToTzSpecificLocalTimeEx"
    ((ptr void) @-> (ptr void) @-> (ptr void) @-> returning int32_t)
(* lpTimeZoneInformation : DYNAMIC_TIME_ZONE_INFORMATION* optional -> (ptr void) *)
(* lpUniversalTime : SYSTEMTIME* -> (ptr void) *)
(* lpLocalTime : SYSTEMTIME* out -> (ptr void) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library kernel32 (t "KERNEL32.dll"))
(cffi:use-foreign-library kernel32)

(cffi:defcfun ("SystemTimeToTzSpecificLocalTimeEx" system-time-to-tz-specific-local-time-ex :convention :stdcall) :int32
  (lp-time-zone-information :pointer)   ; DYNAMIC_TIME_ZONE_INFORMATION* optional
  (lp-universal-time :pointer)   ; SYSTEMTIME*
  (lp-local-time :pointer))   ; SYSTEMTIME* out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $SystemTimeToTzSpecificLocalTimeEx = Win32::API::More->new('KERNEL32',
    'BOOL SystemTimeToTzSpecificLocalTimeEx(LPVOID lpTimeZoneInformation, LPVOID lpUniversalTime, LPVOID lpLocalTime)');
# my $ret = $SystemTimeToTzSpecificLocalTimeEx->Call($lpTimeZoneInformation, $lpUniversalTime, $lpLocalTime);
# lpTimeZoneInformation : DYNAMIC_TIME_ZONE_INFORMATION* optional -> LPVOID
# lpUniversalTime : SYSTEMTIME* -> LPVOID
# lpLocalTime : SYSTEMTIME* out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

類似 API
使用する型