static void Main(string[] args) { TIME_ZONE_INFORMATION tz = new TIME_ZONE_INFORMATION(); GetTimeZoneInformation(ref tz); string s = args[0]; System.Globalization.DateTimeFormatInfo dtfi = new System.Globalization.DateTimeFormatInfo(); dtfi.FullDateTimePattern = "dd/MM/yyyy HH:mm:ss zz"; dtfi.DateSeparator = "/"; dtfi.TimeSeparator = ":"; DateTime dt = DateTime.Parse(s, dtfi); SYSTEMTIME time = new SYSTEMTIME(dt); //time.wDay = (ushort)dt.Day; //time.wHour = (ushort)dt.Hour; //time.wDayOfWeek = (ushort)dt.DayOfWeek; //time.wMilliseconds = (ushort)dt.Millisecond; //time.wMinute = (ushort)dt.Minute; //time.wMonth = (ushort)dt.Month; //time.wSecond = (ushort)dt.Second; //time.wYear = (ushort)dt.Year; SetSystemTime(ref time); }
private static void Main(string[] args) { if (args.Length == 5) { var time = new SYSTEMTIME { wDay = ushort.Parse(args[0]), wMonth = ushort.Parse(args[1]), wYear = ushort.Parse(args[2]), wHour = ushort.Parse(args[3]), wMinute = ushort.Parse(args[4]) }; SetTime(time); return; } if (File.Exists("date.txt")) { var tr = new StreamReader("date.txt"); string dateString = tr.ReadLine(); if (dateString != null) { dateString = dateString.Trim(); DateTime convertedDate = DateTime.Parse(dateString); SetTime(convertedDate); } } else { SetTime(1, 1, 2012, 12, 00); } }
static void Main(string[] args) { if (args.Length == 0 || (new string[] { "help", "--help", "/?" }).Contains(args[0])) { System.Console.WriteLine("Give as the only parameter the time difference in hours. For example \"SetClock.exe -2\" moves the clock two hours backwards."); return; } double delta = 0; try { delta = Convert.ToDouble(args[0]); } catch { System.Console.WriteLine("Error converting input parameter to time difference."); return; } var newDateTime = DateTime.Now.ToUniversalTime().AddHours(delta); var newSystemTime = new SYSTEMTIME(); newSystemTime.wYear = Convert.ToInt16(newDateTime.Year); newSystemTime.wMonth = Convert.ToInt16(newDateTime.Month); newSystemTime.wDay = Convert.ToInt16(newDateTime.Day); newSystemTime.wDayOfWeek = Convert.ToInt16(newDateTime.DayOfWeek); newSystemTime.wHour = Convert.ToInt16(newDateTime.Hour); newSystemTime.wMinute = Convert.ToInt16(newDateTime.Minute); newSystemTime.wSecond = Convert.ToInt16(newDateTime.Second); newSystemTime.wMilliseconds = Convert.ToInt16(newDateTime.Millisecond); SetSystemTime(ref newSystemTime); }
private void GetTime() { SYSTEMTIME stime = new SYSTEMTIME(); GetSystemTime(out stime); //labTime.Text = "Current Time:" + stime.wYear.ToString() + "/" + stime.wMonth.ToString() + "/" + stime.wDay.ToString() + " " + stime.wHour.ToString() +":"+ stime.wMinute.ToString() +":"+ stime.wSecond.ToString(); //lblError.Text = DateTime.Now.ToString("yyyyMMdd"); }
private void ChangeDateDown(int numDays) { DateTime t = DateTime.Now.AddDays(-1); DateTime h = DateTime.Now.AddHours(0); SYSTEMTIME st = new SYSTEMTIME(); st.FromDateTime(t); SetSystemTime(ref st); }
public REGISTRY_TIME_ZONE_INFORMATION(TIME_ZONE_INFORMATION tzi) { Bias = tzi.Bias; StandardDate = tzi.StandardDate; StandardBias = tzi.StandardBias; DaylightDate = tzi.DaylightDate; DaylightBias = tzi.DaylightBias; }
public static void SetTime(SYSTEMTIME time) { if (!SetLocalTime(ref time)) { // The native function call failed, so throw an exception throw new Win32Exception(Marshal.GetLastWin32Error()); } }
public static void SetTime(ushort day, ushort month, ushort year, ushort hour, ushort minute) { var time = new SYSTEMTIME {wDay = day, wMonth = month, wYear = year, wHour = hour, wMinute = minute}; if (!SetLocalTime(ref time)) { // The native function call failed, so throw an exception throw new Win32Exception(Marshal.GetLastWin32Error()); } }
/// <summary> /// Gets current system time. /// </summary> /// <returns></returns> public static DateTime GetTime() { // Call the native GetSystemTime method // with the defined structure. SYSTEMTIME stime = new SYSTEMTIME(); GetSystemTime(ref stime); var utc = new DateTime(stime.wYear, stime.wMonth, stime.wDay, stime.wHour, stime.wMinute, stime.wSecond, stime.wMilliseconds, DateTimeKind.Utc); return utc.ToLocalTime(); }
// SYSTEMTIME�\���� // // ABSTRACT : DateTime�R���g���[���Ƀ��b�Z�[�W�𑗂� // public static System.IntPtr SetSystemTime( int pid , // �^�[�Q�b�g�̃v���Z�XID System.IntPtr hDateTime , // DATETIME�R���g���[���n���h�� SYSTEMTIME sysTime ) { System.IntPtr hAccess; System.IntPtr mem; System.IntPtr result; GCHandle gctemp; int n; hAccess = InterProcess.OpenProcess( InterProcess.PROCESS_VM_OPERATION | InterProcess.PROCESS_VM_READ | InterProcess.PROCESS_VM_WRITE , 0 , pid ); mem = InterProcess.VirtualAllocEx( hAccess , (System.IntPtr)0 , 4096 , InterProcess.MEM_COMMIT | InterProcess.MEM_RESERVE , InterProcess.PAGE_READWRITE ); // �\���̂�v���Z�X�ɏ������� gctemp = GCHandle.Alloc( sysTime, GCHandleType.Pinned ); System.IntPtr a = gctemp.AddrOfPinnedObject(); InterProcess.WriteProcessMemory( hAccess , mem , a , Marshal.SizeOf( sysTime ), out n ); result = Window.SendMessage( hDateTime , DTM_SETSYSTEMTIME , System.IntPtr.Zero , // GDT_VALID mem ); gctemp.Free(); InterProcess.VirtualFreeEx( hAccess, mem, 4096, InterProcess.MEM_RELEASE ); return result; }
public static void SetLocalTime(DateTime time) { var newTime = new SYSTEMTIME { wYear = (ushort)time.Year, wMonth = (ushort)time.Month, wDay = (ushort)time.Day, wHour = (ushort)time.Hour, wMinute = (ushort)time.Minute, wSecond = (ushort)time.Second, wMilliseconds = (ushort)time.Millisecond }; SetLocalTime(ref newTime); }
/// <summary> /// Sets current system time. /// </summary> /// <param name="dateTime">Time to set as current system time.</param> public static void SetTime(DateTime dateTime) { dateTime = dateTime.ToUniversalTime(); SYSTEMTIME stime = new SYSTEMTIME() { wYear = (ushort)dateTime.Year, wMonth = (ushort)dateTime.Month, wDay = (ushort)dateTime.Day, wHour = (ushort)dateTime.Hour, wMinute = (ushort)dateTime.Minute, wSecond = (ushort)dateTime.Second, wMilliseconds = (ushort)dateTime.Millisecond }; SetSystemTime(ref stime); }
static void Main(string[] args) { string s = args[0]; System.Globalization.DateTimeFormatInfo dtfi = new System.Globalization.DateTimeFormatInfo(); dtfi.FullDateTimePattern = "dd/MM/yyyy HH:mm:ss"; dtfi.ShortDatePattern = "dd/MM/yyyy"; dtfi.ShortTimePattern = "HH:mm:ss"; dtfi.DateSeparator = "/"; dtfi.TimeSeparator = ":"; string s1 = DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss",dtfi); string s2 = s.Remove(s.Length - 4,4); string s3 = s.Substring(s.Length - 4, 4); DateTime dt = DateTime.Parse(s2, dtfi); SYSTEMTIME time = new SYSTEMTIME(dt); //time.wDay = (ushort)dt.Day; //time.wHour = (ushort)dt.Hour; //time.wDayOfWeek = (ushort)dt.DayOfWeek; //time.wMilliseconds = (ushort)dt.Millisecond; //time.wMinute = (ushort)dt.Minute; //time.wMonth = (ushort)dt.Month; //time.wSecond = (ushort)dt.Second; //time.wYear = (ushort)dt.Year; SetLocalTime(ref time); TIME_ZONE_INFORMATION tzI = new TIME_ZONE_INFORMATION(); GetTimeZoneInformation(ref tzI); tzI.Bias = int.Parse(s3)*60; tzI.StandardBias = 0; //tzI.DaylightBias = 0; //tzI.StandardName = "Moscow"; //tzI.DaylightName = "Moscow"; //tzI.DaylightDate = time; //tzI.StandardDate = time; SetTimeZoneInformation(ref tzI); Microsoft.Win32.Registry.LocalMachine.Flush(); }
public static void SetTime(DateTime timed) { var time = new SYSTEMTIME { wDay = (ushort) timed.Day, wMonth = (ushort) timed.Month, wYear = (ushort) timed.Year, wHour = (ushort) timed.Hour, wMinute = (ushort) timed.Minute }; if (!SetLocalTime(ref time)) { // The native function call failed, so throw an exception throw new Win32Exception(Marshal.GetLastWin32Error()); } }
///<summary>Set the windows system time.</summary> public static void SetTime(DateTime newTime) { // Call the native SetLocalTime method // with the defined structure. SYSTEMTIME systime=new SYSTEMTIME(); systime.wYear=(ushort)newTime.Year; systime.wMonth=(ushort)newTime.Month; systime.wDayOfWeek=(ushort)newTime.DayOfWeek; systime.wDay=(ushort)newTime.Day; systime.wHour=(ushort)newTime.Hour; systime.wMinute=(ushort)newTime.Minute; systime.wSecond=(ushort)newTime.Second; systime.wMilliseconds=(ushort)newTime.Millisecond; SetLocalTime(ref systime); string messageText="System date and time set to: "+newTime.ToString("MM/dd/yyyy hh:mm:ss.fff tt")+"."; EventLog.WriteEntry("OpenDental",messageText,EventLogEntryType.Information); }
public DigitalClockDisplay(bool is24Hour, bool suppressExtra) { f24Hour = is24Hour; fSuppress = suppressExtra; fSegmentedNumber = new SegmentedNumber(); ptColon = new Point[2][]; ptColon[0] = new Point[] { new Point(2, 21), new Point(6, 17), new Point(10, 21), new Point(6, 25) }; ptColon[1] = new Point[] { new Point(2, 51), new Point(6, 47), new Point(10, 51), new Point(6, 55) }; fcolonPolies = new PolygonG[2]; fcolonPolies[0] = new PolygonG(ptColon[0]); fcolonPolies[1] = new PolygonG(ptColon[1]); fLastTime = new SYSTEMTIME(); fThisTime = new SYSTEMTIME(); }
public BLUETOOTH_DEVICE_INFO(long address) { dwSize = 560; this.Address = address; ulClassofDevice = 0; fConnected = false; fRemembered = false; fAuthenticated = false; #if WinXP stLastSeen = new SYSTEMTIME(); stLastUsed = new SYSTEMTIME(); // The size is much smaller on CE (no times and string not inline) it // appears to ignore the bad dwSize value. So don't check this on CF. System.Diagnostics.Debug.Assert(Marshal.SizeOf(typeof(BLUETOOTH_DEVICE_INFO)) == dwSize, "BLUETOOTH_DEVICE_INFO SizeOf == dwSize"); #endif szName = ""; }
int IVsSolutionEventsProjectUpgrade.OnAfterUpgradeProject(IVsHierarchy pHierarchy, uint fUpgradeFlag, string bstrCopyLocation, SYSTEMTIME stUpgradeTime, IVsUpgradeLogger pLogger) { Debug.Assert(pHierarchy != null); Project upgradedProject = VsUtility.GetProjectFromHierarchy(pHierarchy); if (upgradedProject != null) { IList<IPackage> packagesToBeReinstalled = ProjectRetargetingUtility.GetPackagesToBeReinstalled(upgradedProject); if (!packagesToBeReinstalled.IsEmpty()) { pLogger.LogMessage((int)__VSUL_ERRORLEVEL.VSUL_ERROR, upgradedProject.Name, upgradedProject.Name, String.Format(CultureInfo.CurrentCulture, Resources.ProjectUpgradeAndRetargetErrorMessage, String.Join(", ", packagesToBeReinstalled.Select(p => p.Id)))); } } return VSConstants.S_OK; }
public static void SetTime(DateTime dt) { // Call the native GetSystemTime method // with the defined structure. SYSTEMTIME systime = new SYSTEMTIME(); //GetSystemTime(ref systime); systime.wDay = (ushort)dt.Day; systime.wMonth = (ushort)dt.Month; systime.wYear = (ushort)dt.Year; systime.wHour = (ushort)dt.Hour; systime.wMinute = (ushort)dt.Minute; systime.wSecond = (ushort)dt.Second; // Set the system clock ahead one hour. //systime.wHour = (ushort)(systime.wHour + 1 % 24); SetSystemTime(ref systime); System.Diagnostics.Debug.WriteLine(string.Format("New time: " + systime.wHour.ToString() + ":" + systime.wMinute.ToString()+"\r\n")); }
public unsafe TIME_ZONE_INFORMATION(TIME_DYNAMIC_ZONE_INFORMATION dtzi) { Bias = dtzi.Bias; fixed (char* standard = StandardName) { for (int i = 0; i < 32; ++i) { standard[i] = dtzi.StandardName[i]; } } fixed (char* daylight = DaylightName) { for (int i = 0; i < 32; ++i) { daylight[i] = dtzi.DaylightName[i]; } } StandardDate = dtzi.StandardDate; StandardBias = dtzi.StandardBias; DaylightDate = dtzi.DaylightDate; DaylightBias = dtzi.DaylightBias; }
public static DateTime GetTime() { // Call the native GetSystemTime method // with the defined structure. SYSTEMTIME stime = new SYSTEMTIME(); GetSystemTime(ref stime); // Show the current time. string strDateTime=( stime.wDay.ToString() + "." + stime.wMonth.ToString() + "." + stime.wYear.ToString() + " "+ stime.wHour.ToString() + ":"+ stime.wMinute.ToString()+":"+stime.wSecond.ToString() ); DateTime dt; try { dt = DateTime.Parse(strDateTime); } catch (SystemException sx) { System.Diagnostics.Debug.WriteLine("Exception in GetTime(): " + sx.Message + "\r\n"); dt=DateTime.Now; } return dt; }
/// <summary> /// 静态方法。转换为System.DateTime类型。 /// </summary> /// <param name="time">SYSTEMTIME类型的时间。</param> /// <returns></returns> public static DateTime ToDateTime(SYSTEMTIME time) { return(time.ToDateTime()); }
static extern bool SystemTimeToFileTime(ref SYSTEMTIME lpSystemTime, ref FILETIME lpFileTime);
private static extern bool SystemTimeToFileTime([In] ref SYSTEMTIME lpSystemTime, out System.Runtime.InteropServices.ComTypes.FILETIME lpFileTime);
public static extern long FileTimeToSystemTime(ref FILETIME FileTime, ref SYSTEMTIME SystemTime);
private extern static void GetSystemTime(ref SYSTEMTIME lpSystemTime);
public void SessionUpdated(Object session, SYSTEMTIME sysTime, Boolean toKillProcesses) { SystemTime.SetSystemTime(ref sysTime); ESessionUpdated(session, toKillProcesses); }
/// <summary>クライアント生成 - Writeスレッド関数</summary> private void WriteSharedMemory() { // 共有メモリ(サーバ) SharedMemory sm = null; // スレッドID int managedThreadId = Thread.CurrentThread.ManagedThreadId; try { // 共有メモリを生成(256バイト) sm = new SharedMemory("my-sm", 256, "my-mtx"); // マップ sm.Map(0, 0); // ロック sm.Lock(); // システム時間、ローカル時間の「Manage SYSTEMTIME構造体」 SYSTEMTIME[] csts = new SYSTEMTIME[2]; // システム時間 CmnWin32.GetSystemTime(out csts[0]); string systemTime = string.Format("{0:0000}/{1:00}/{2:00} {3:00}:{4:00}:{5:00}.{6:000}", csts[0].Year, csts[0].Month, csts[0].Day, csts[0].Hour, csts[0].Minute, csts[0].Second, csts[0].Milliseconds); // ローカル時間 CmnWin32.GetLocalTime(out csts[1]); string localTime = string.Format("{0:0000}/{1:00}/{2:00} {3:00}:{4:00}:{5:00}.{6:000}", csts[1].Year, csts[1].Month, csts[1].Day, csts[1].Hour, csts[1].Minute, csts[1].Second, csts[1].Milliseconds); // 共有メモリを初期化 sm.SetMemory(CmnClass.InitBuff(256), 256); // マーシャリング(「Unmanage SYSTEMTIME構造体」のバイト表現を取得) //// (1) //SYSTEMTIME cst = new SYSTEMTIME(); //int sizeCst = Marshal.SizeOf(cst); //byte[] cstBytes = new byte[sizeCst]; //byte[] cstsBytes = new byte[sizeCst * 2]; //Array.Copy(CustomMarshaler.StructureToBytes(csts[0]), 0, cstsBytes, 0, sizeCst); //Array.Copy(CustomMarshaler.StructureToBytes(csts[1]), 0, cstsBytes, sizeCst * 1, sizeCst); // (2) byte[] cstsBytes = CustomMarshaler.StructuresToBytes(new object[] { csts[0], csts[1] }, 2); // 共有メモリへ書き込む。 sm.SetMemory(cstsBytes, cstsBytes.Length); // 送信メッセージを表示 this.SetResult_Client( string.Format("({0})送信:{1}", managedThreadId, "\r\nsystemTime:" + systemTime + "\r\nlocalTime:" + localTime)); } catch (Exception ex) { // エラーを表示 this.SetResult_Client( string.Format("({0})エラー:{1}", managedThreadId, ex.ToString())); } finally { if (sm != null) { // 共有メモリをクローズ // アンロック&マネージ・アンマネージリソースの解放 sm.Close();// ←コメントアウトするとGC任せになるが、ミューテックスの解放が遅れる! } } }
static string GetCurrentYear() { SYSTEMTIME st = new SYSTEMTIME(); GetSystemTime(ref st); return st.wYear.ToString(); }
public static extern bool FileTimeToSystemTime([In] ref FILETIME lpFileTime, out SYSTEMTIME lpSystemTime);
int IVsSolutionEventsProjectUpgrade.OnAfterUpgradeProject(IVsHierarchy pHierarchy, uint fUpgradeFlag, string bstrCopyLocation, SYSTEMTIME stUpgradeTime, IVsUpgradeLogger pLogger) { NuGetUIThreadHelper.JoinableTaskFactory.Run(async delegate { await NuGetUIThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); Debug.Assert(pHierarchy != null); var upgradedProject = VsHierarchyUtility.GetProjectFromHierarchy(pHierarchy); var upgradedNuGetProject = await EnvDTEProjectUtility.GetNuGetProjectAsync(upgradedProject, _solutionManager); if (ProjectRetargetingUtility.IsProjectRetargetable(upgradedNuGetProject)) { var packagesToBeReinstalled = await ProjectRetargetingUtility.GetPackagesToBeReinstalled(upgradedNuGetProject); if (packagesToBeReinstalled.Any()) { pLogger.LogMessage((int)__VSUL_ERRORLEVEL.VSUL_ERROR, upgradedProject.Name, upgradedProject.Name, string.Format(CultureInfo.CurrentCulture, Strings.ProjectUpgradeAndRetargetErrorMessage, string.Join(", ", packagesToBeReinstalled.Select(p => p.Id)))); } } }); return(VSConstants.S_OK); }
private static extern bool SetLocalTime(ref SYSTEMTIME lpSystemTime);
void DecryptHelper4(byte[] data, int index, uint[] key_src) { uint[] buf = new uint[0x50]; int i; for (i = 0; i < 0x10; ++i) { buf[i] = BigEndian.ToUInt32(data, index + 40 + 4 * i); } for (; i < 0x50; ++i) { uint v = buf[i - 16]; v ^= buf[i - 14]; v ^= buf[i - 8]; v ^= buf[i - 3]; buf[i] = Binary.RotL(v, 1); } uint[] key = new uint[10]; Array.Copy(key_src, key, 5); uint k0 = key[0]; uint k1 = key[1]; uint k2 = key[2]; uint k3 = key[3]; uint k4 = key[4]; for (int buf_idx = 0; buf_idx < 0x50; ++buf_idx) { uint f, c; if (buf_idx < 0x10) { f = k1 ^ k2 ^ k3; c = 0; } else if (buf_idx < 0x20) { f = k1 & k2 | k3 & ~k1; c = 0x5A827999; } else if (buf_idx < 0x30) { f = k3 ^ (k1 | ~k2); c = 0x6ED9EBA1; } else if (buf_idx < 0x40) { f = k1 & k3 | k2 & ~k3; c = 0x8F1BBCDC; } else { f = k1 ^ (k2 | ~k3); c = 0xA953FD4E; } uint new_k0 = buf[buf_idx] + k4 + f + c + Binary.RotL(k0, 5); uint new_k2 = Binary.RotR(k1, 2); k1 = k0; k4 = k3; k3 = k2; k2 = new_k2; k0 = new_k0; } key[0] += k0; key[1] += k1; key[2] += k2; key[3] += k3; key[4] += k4; var ft = new FILETIME { DateTimeLow = key[1], DateTimeHigh = key[0] & 0x7FFFFFFF }; var sys_time = new SYSTEMTIME(ft); key[5] = (uint)(sys_time.Year | sys_time.Month << 16); key[7] = (uint)(sys_time.Hour | sys_time.Minute << 16); key[8] = (uint)(sys_time.Second | sys_time.Milliseconds << 16); uint flags = LittleEndian.ToUInt32(data, index + 40) | 0x80000000; uint rgb = buf[1] >> 8; // BigEndian.ToUInt32 (data, index+44) >> 8; if (0 == (flags & 0x78000000)) { flags |= 0x98000000; } key[6] = RegionCrc32(m_scheme.Region, flags, rgb); key[9] = (uint)(((int)key[2] * (long)(int)key[3]) >> 8); if (m_scheme.Version >= 2390) { key[6] += key[9]; } unsafe { fixed(byte *data_fixed = data) { uint *encoded = (uint *)(data_fixed + index); for (i = 0; i < 10; ++i) { encoded[i] ^= key[i]; } } } }
static extern void GetSystemTime(ref SYSTEMTIME lpSystemTime);
static extern int SetSystemTime(ref SYSTEMTIME lpSystemTime);
public static extern long SystemTimeToTzSpecificLocalTime(IntPtr lpTimeZoneInformation, ref SYSTEMTIME lpUniversalTime, out SYSTEMTIME lpLocalTime);
/// <summary>サーバ起動 - pollingスレッド関数</summary> /// <remarks>unsafeキーワードが必要になる</remarks> private void PollingSharedMemory() { // 共有メモリ(サーバ) SharedMemory sm = null; // スレッドID int managedThreadId = Thread.CurrentThread.ManagedThreadId; try { // 共有メモリを生成 sm = new SharedMemory("my-sm", 256, "my-mtx"); // マップ sm.Map(0, 0); // Polling開始を表示 this.SetResult_Svr( string.Format("Polling開始! - ThreadId:{0}", managedThreadId)); // Polling処理 while (!End) { // システム時間、ローカル時間の「Manage SYSTEMTIME構造体」 SYSTEMTIME cst = new SYSTEMTIME(); byte[] cstBytes = new byte[Marshal.SizeOf(cst)]; byte[] cstsBytes = new byte[Marshal.SizeOf(cst) * 2]; // 共有メモリから「Unmanage SYSTEMTIME構造体」配列のバイト表現を読み込む。 sm.GetMemory(out cstsBytes, cstsBytes.Length); // マーシャリング(「Unmanage SYSTEMTIME構造体」配列のバイト表現を「Manage SYSTEMTIME構造体」へ変換) //// (1) //object[] os = new object[2]; //Array.Copy(cstsBytes, 0, cstBytes, 0, Marshal.SizeOf(cst)); //os[0] = CustomMarshaler.BytesToStructure(cstBytes, typeof(SYSTEMTIME)); //Array.Copy(cstsBytes, Marshal.SizeOf(cst) * 1, cstBytes, 0, Marshal.SizeOf(cst)); //os[1] = CustomMarshaler.BytesToStructure(cstBytes, typeof(SYSTEMTIME)); // (2) object[] os = CustomMarshaler.BytesToStructures(cstsBytes, typeof(SYSTEMTIME), 2); SYSTEMTIME[] csts = new SYSTEMTIME[] { (SYSTEMTIME)os[0], (SYSTEMTIME)os[1] }; // システム時間 string systemTime = string.Format("{0:0000}/{1:00}/{2:00} {3:00}:{4:00}:{5:00}.{6:000}", csts[0].Year, csts[0].Month, csts[0].Day, csts[0].Hour, csts[0].Minute, csts[0].Second, csts[0].Milliseconds); // ローカル時間 string localTime = string.Format("{0:0000}/{1:00}/{2:00} {3:00}:{4:00}:{5:00}.{6:000}", csts[1].Year, csts[1].Month, csts[1].Day, csts[1].Hour, csts[1].Minute, csts[1].Second, csts[1].Milliseconds); // 受信メッセージを表示 this.SetResult_Svr( string.Format("({0})受信:{1}", managedThreadId, "\r\nsystemTime:" + systemTime + "\r\nlocalTime:" + localTime)); Thread.Sleep(1000); // Polling間隔 } // Polling停止を表示 this.SetResult_Svr( string.Format("Polling停止! - ThreadId:{0}", managedThreadId)); } catch (Exception ex) { // エラーを表示 this.SetResult_Svr( string.Format("({0})エラー:{1}", managedThreadId, ex.ToString())); } finally { if (sm != null) { // 共有メモリをクローズ // アンロック&マネージ・アンマネージリソースの解放 sm.Close();// ←コメントアウトするとGC任せになるが、ミューテックスの解放が遅れる! } } }
public static extern Boolean FileTimeToSystemTime(ref winapi.Components.FILETIME lpFileTime, out SYSTEMTIME lpSystemTime);
private extern static uint SetSystemTime(ref SYSTEMTIME lpSystemTime);
static DateTime getDateTime(SYSTEMTIME systemTime) { DateTime dt = new DateTime(systemTime.Year, systemTime.Month, systemTime.Day, systemTime.Hour, systemTime.Minute, systemTime.Second); return(dt); }
public static extern bool SetSystemTime(ref SYSTEMTIME st);
public void SetDateTime(SYSTEMTIME systemTime) { SetSystemTime(ref systemTime); }
public static extern long SystemTimeToTzSpecificLocalTime(IntPtr lpTimeZoneInformation, ref SYSTEMTIME lpUniversalTime, out SYSTEMTIME lpLocalTime);
private static extern bool FileTimeToSystemTime (ref System.Runtime.InteropServices.ComTypes.FILETIME FileTime, ref SYSTEMTIME SystemTime);
public static extern bool GetSystemTime(out SYSTEMTIME systemTime);
public static extern bool SetLocalTime(ref SYSTEMTIME st);
internal static extern bool SetLocalTime(ref SYSTEMTIME lpSystemTime);
static SYSTEMTIME getSystemTime(DateTime dt) { SYSTEMTIME st = new SYSTEMTIME(dt); return(st); }
public static extern int DLL_AddCountDown(ref RECT rect, int transparent, string fontname, int fontsize, int fontcolor, int format, ref SYSTEMTIME endtime, int fontstyle);
private static extern int FileTimeToSystemTime(ref FILETIME lpFileTime, ref SYSTEMTIME lpSystemTime);
public static void SetNewSysTime(DateTime dateTime) { SYSTEMTIME st = new SYSTEMTIME(dateTime); Console.WriteLine("Time has been set: " + dateTime.ToLocalTime()); SetSystemTime(ref st); }
public int AddCountDown(ref RECT rect, int transparent, string fontname, int fontsize, int fontcolor, eCountType format, ref SYSTEMTIME endtime, int fontstyle) { return(DLL_AddCountDown(ref rect, transparent, fontname, fontsize, fontcolor, (int)format, ref endtime, fontstyle)); }
static extern void GetSystemTime(ref SYSTEMTIME lpSystemTime);
public static extern void DLL_GetLocalTime(ref SYSTEMTIME lpSystemTime);
public static extern long FileTimeToSystemTime(ref FILETIME FileTime, ref SYSTEMTIME SystemTime);
/// <summary> /// 获取当前系统时间 /// </summary> /// <param name="lpSystemTime">系统时间变量</param> /// <returns></returns> public void GetLocalTime(ref SYSTEMTIME lpSystemTime) { DLL_GetLocalTime(ref lpSystemTime); }
public static extern bool SetSystemTime(ref SYSTEMTIME st);
private static extern bool SetSystemTime(ref SYSTEMTIME st);
//Then call the method with an instance of your struct like this: void SetSysDateTime(int year,int month,int day,int hour,int min,int sec) { SYSTEMTIME st = new SYSTEMTIME(); st.wYear = (short)year; // must be short st.wMonth = (short)month; st.wDay = (short)day; st.wHour =(short)hour; st.wMinute = (short)min; st.wSecond = (short)sec; SetLocalTime(ref st); }
private static extern bool SetLocalTime(ref SYSTEMTIME time);