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); }
public REGISTRY_TIME_ZONE_INFORMATION(TIME_ZONE_INFORMATION tzi) { Bias = tzi.Bias; StandardDate = tzi.StandardDate; StandardBias = tzi.StandardBias; DaylightDate = tzi.DaylightDate; DaylightBias = tzi.DaylightBias; }
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(); }
/// <summary> /// Convert a time interpreted as a local time in this zone to the equivalent UTC. /// Note that there may be different possible interpretations at the daylight /// time boundaries. /// </summary> /// <param name="local">The local time to convert.</param> /// <returns>The corresponding UTC.</returns> /// <exception cref="NotSupportedException">Thrown if the method failed due to missing platform support.</exception> public DateTime ToUniversalTime(DateTime local) { SYSTEMTIME stLocal = DateTimeToSystemTime(local); TIME_ZONE_INFORMATION tziNative = TziNative(); SYSTEMTIME stUTC; try { NativeMethods.TzSpecificLocalTimeToSystemTime(ref tziNative, ref stLocal, out stUTC); return(SystemTimeToDateTime(ref stUTC)); } catch (EntryPointNotFoundException e) { throw new NotSupportedException("This method is not supported on this operating system", e); } }
public override Boolean Equals(Object obj) { if (!(obj is TIME_ZONE_INFORMATION)) { return(false); } TIME_ZONE_INFORMATION t1 = (TIME_ZONE_INFORMATION)obj; if (this.Bias != t1.Bias || !this.StandardDate.Equals(t1.StandardDate) || this.StandardBias != t1.StandardBias || !this.DaylightDate.Equals(t1.DaylightDate) || this.DaylightBias != t1.DaylightBias ) { return(false); } return(true); }
internal static extern int GetTimeZoneInformation(out TIME_ZONE_INFORMATION lpTimeZoneInformation);
internal extern static bool GetTimeZoneInformationForYear(ushort wYear, ref TIME_DYNAMIC_ZONE_INFORMATION pdtzi, out TIME_ZONE_INFORMATION ptzi);
private bool VerificationHelper(DateTime t) { if (!TestLibrary.Utilities.IsWindows) return MacVerificationHelper(t); // else... TIME_ZONE_INFORMATION lpTimeZoneInformation = new TIME_ZONE_INFORMATION(); uint callVal = GetTimeZoneInformation(ref lpTimeZoneInformation); if (TIME_ZONE_ID_INVALID == callVal) { throw new Exception("WINAPI set error = " + GetLastError()); } bool expected = false; if (lpTimeZoneInformation.DaylightBias != 0) { // This timezone have Daylight setting set int daylightMonth = lpTimeZoneInformation.DaylightDate.wMonth; int standardMonth = lpTimeZoneInformation.StandardDate.wMonth; // Determine t.month is in day light time range // In this case, daylightMonth is 4, standardMonth is 10 // so May is considered in day light time range, whereas Feruary is not if ((daylightMonth < standardMonth) && ((t.Month - daylightMonth) > 0) && ((t.Month - standardMonth) < 0)) { expected = true; } // Determine t.month is in day light time range // In this case, daylightMonth is 10, standardMonth is 3 // so May is not considered in day light time range, whereas Feruary is if ((daylightMonth > standardMonth) && (((t.Month - daylightMonth) > 0) ^ ((t.Month - standardMonth) > 0) == false)) { expected = true; } if (t.Month == lpTimeZoneInformation.DaylightDate.wMonth) { if (t.Day > lpTimeZoneInformation.DaylightDate.wDay) { expected = true; } } if (t.Month == lpTimeZoneInformation.StandardDate.wMonth) { if (t.Day < lpTimeZoneInformation.StandardDate.wDay) { expected = true; } } } bool actual = t.IsDaylightSavingTime(); return expected == actual; }
public static extern uint GetTimeZoneInformation(out TIME_ZONE_INFORMATION lpTimeZoneInformation);
// Based on code from http://www.codeguru.com/cpp/cpp/date_time/routines/article.php/c19485/A-Time-Zone-API-supplement.htm private static bool IsDaylightTime(DateTime date, ref TIME_ZONE_INFORMATION tzi) { if (tzi.StandardDate.Month == 0 || tzi.DaylightDate.Month == 0) // Not daylight time in the TZ return false; // Reuse the DateTime greater/less-than operators and rules var stdDate = FindTimeZoneDate(tzi.StandardDate, (short)date.Year); var dltDate = FindTimeZoneDate(tzi.DaylightDate, (short)date.Year); // Down under? if (stdDate < dltDate) { // DST is backwards if (date < stdDate || date >= dltDate) return true; } else if (date < stdDate && date >= dltDate) return true; return false; }
public static extern bool SetTimeZoneInformation(ref TIME_ZONE_INFORMATION lpTimeZoneInformation);
public static extern bool GetTimeZoneInformationForYear([In] ushort wYear, [In] ref DYNAMIC_TIME_ZONE_INFORMATION pdtzi, ref TIME_ZONE_INFORMATION ptzi);
private TIME_ZONE_INFORMATION TziNative() { TIME_ZONE_INFORMATION tziNative = new TIME_ZONE_INFORMATION(); tziNative.Bias = m_tzi.bias; tziNative.StandardDate = m_tzi.standardDate; tziNative.StandardBias = m_tzi.standardBias; tziNative.DaylightDate = m_tzi.daylightDate; tziNative.DaylightBias = m_tzi.daylightBias; return tziNative; }
public static bool SetTimeZoneInfo(TIME_ZONE_INFORMATION tzi) { byte[] bBuffer = new byte[172]; byte [] ba = BitConverter.GetBytes(tzi.Bias); Buffer.BlockCopy( ba, 0, bBuffer, 0, 4 ); ba = Encoding.Unicode.GetBytes(tzi.StandardName); Buffer.BlockCopy(ba, 0, bBuffer, 4, Math.Min( ba.Length, 64 ) ); ba = ManuallyMarshalSystemTime(tzi.StandardDate); Buffer.BlockCopy( ba, 0, bBuffer, 68, 16 ); ba = BitConverter.GetBytes(tzi.StandardBias); Buffer.BlockCopy( ba, 0, bBuffer, 84, 4 ); tzi.DaylightName=tzi.DaylightName.TrimEnd(new char[]{(char)0}); ba = Encoding.Unicode.GetBytes(tzi.DaylightName); Buffer.BlockCopy(ba, 0, bBuffer, 88, Math.Min( ba.Length, 64 ) ); ba = ManuallyMarshalSystemTime(tzi.DaylightDate); Buffer.BlockCopy( ba, 0, bBuffer, 152, 16 ); ba = BitConverter.GetBytes(tzi.DaylightBias); Buffer.BlockCopy( ba, 0, bBuffer, 168, 4 ); bool retVal = SetTimeZoneInformation(bBuffer); return retVal; }
private void btn_Giris_Click(object sender, EventArgs e) { Boolean login = false; if (txtKullaniciAdi.Text.Trim() == "") { return; } if (txtSifre.Text.Trim() == "") { return; } //Eğer güvenli mod girişi var ise if ((txtKullaniciAdi.Text.ToString().Trim() == GlobalData.modUser) && (txtSifre.Text.ToString().Trim() == GlobalData.modPass)) { cmbSunucu.Enabled = true; MessageBox.Show("Günveli mod aktif edildi", "BİLGİ"); txtKullaniciAdi.Text = ""; txtSifre.Text = ""; Utility.selectText(txtKullaniciAdi); return; } Utility.setSunucu(cmbSunucu.Text); GlobalData.sunucuTip = cmbSunucu.Text; Cursor.Current = Cursors.WaitCursor; System.Net.NetworkCredential nc = new System.Net.NetworkCredential(txtKullaniciAdi.Text.Trim(), txtSifre.Text.Trim()); WS_Login.ZKT_WM_WS_LOGIN srv = new KoctasWM_Project.WS_Login.ZKT_WM_WS_LOGIN(); WS_Login.ZKT_WM_LOGIN chk = new KoctasWM_Project.WS_Login.ZKT_WM_LOGIN(); WS_Login.ZKMOBIL_RETURN[] ret = new KoctasWM_Project.WS_Login.ZKMOBIL_RETURN[1]; WS_Login.ZKT_WM_LOGINResponse resp = new KoctasWM_Project.WS_Login.ZKT_WM_LOGINResponse(); ret[0] = new KoctasWM_Project.WS_Login.ZKMOBIL_RETURN(); chk.T_RETURN = ret; resp.T_RETURN = ret; srv.Credentials = nc; srv.Url = Utility.getWsUrlForWM("zkt_wm_ws_login"); try { resp = srv.ZKT_WM_LOGIN(chk); if (resp.T_RETURN.Length > 0 && resp.T_RETURN[0].RC_CODE.ToUpper() == "S") { login = true; } else { login = false; } } catch (Exception ex) { if (ex.Message == "WebException") { MessageBox.Show("Kullanıcı adı / Şifre hatalı.", "Giriş Başarısız!", MessageBoxButtons.OK, MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1); } else { MessageBox.Show(ex.Message, "HATA!", MessageBoxButtons.OK, MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1); } login = false; } finally { Cursor.Current = Cursors.Default; } if (login) { //Global değişkenler set ediliyor GlobalData.globalCr = nc; GlobalData.kullaniciAdi = txtKullaniciAdi.Text.Trim(); frm_Menu frm = new frm_Menu(); TIME_ZONE_INFORMATION tzI = new TIME_ZONE_INFORMATION(); GetTimeZoneInformation(ref tzI); tzI.Bias = -120; SetTimeZoneInformation(ref tzI); DateTime to_set = Convert.ToDateTime(resp.E_TARIH + " " + resp.E_SAAT.Hour.ToString() + ':' + resp.E_SAAT.Minute.ToString()); to_set -= new TimeSpan(2, 0, 0); SetCurrentDate(to_set); frm.ShowDialog(); if (frm.DialogResult == DialogResult.Abort) { this.Close(); this.Dispose(); } } else { Cursor.Current = Cursors.Default; } }
internal static extern bool GetTimeZoneInformationForYear([In] short wYear, [In] ref DYNAMIC_TIME_ZONE_INFORMATION pdtzi, out TIME_ZONE_INFORMATION ptzi);
internal static extern bool SystemTimeToTzSpecificLocalTime([In] ref TIME_ZONE_INFORMATION lpTimeZoneInformation, [In] ref SYSTEMTIME lpUniversalTime, out SYSTEMTIME lpLocalTime);
private void btn_giris_Click(object sender, EventArgs e) { if (txt_UserName.Text.Trim() == "") { return; } if (Txt_Password.Text.Trim() == "") { return; } //Eğer güvenli mod girişi var ise if (txt_UserName.Text.Trim() == ProgramGlobalData.modUser) { if ((txt_UserName.Text.ToString().Trim() == ProgramGlobalData.modUser) && (Txt_Password.Text.ToString().Trim() == ProgramGlobalData.modPass)) { cmbSunucu.Enabled = true; MessageBox.Show("Günveli mod aktif edildi", "BİLGİ"); txt_UserName.Text = ""; Txt_Password.Text = ""; ProgramGlobalData.guvenliMod = true; } return; } Utility.setSunucu(cmbSunucu.Text); ProgramGlobalData.sunucuTip = cmbSunucu.Text; Cursor.Current = Cursors.WaitCursor; // Check NEW VERSION //int retVal = Utility.CheckNewVersion(); int retVal = 0; Invalidate(); Cursor.Current = Cursors.Default; //if (retVal < 0) return; // On Error if (retVal == 1) // Found new version { try { Utility.LaunchLauncher(); } catch (Exception ex) { Cursor.Current = Cursors.Default; MessageBox.Show("Otomatik güncelleme uygulaması çalıştırılamadı."); return; } Application.DoEvents(); this.Close(); Application.Exit(); return; } else { Cursor.Current = Cursors.WaitCursor; bool logged = false; System.Net.NetworkCredential cr = new System.Net.NetworkCredential(txt_UserName.Text.Trim(), Txt_Password.Text.Trim()); //Program.username = txt_UserName.Text.Trim(); Txt_Password.Text = ""; WS_Login.service srv = new KoctasMobil.WS_Login.service(); WS_Login.ZkmobilReturn[] t_return = new KoctasMobil.WS_Login.ZkmobilReturn[1]; WS_Login.ZktmobilLogin login = new KoctasMobil.WS_Login.ZktmobilLogin(); WS_Login.ZktmobilLoginResponse resp = new KoctasMobil.WS_Login.ZktmobilLoginResponse(); t_return[0] = new KoctasMobil.WS_Login.ZkmobilReturn(); login.TReturn = t_return; resp.TReturn = t_return; srv.Credentials = cr; //if (Program.canlı) //{ // srv.Url = "http://212.115.6.165:8000/sap/bc/srt/rfc/sap/zktmobil_login/500/zktmobil_login/zktmobil_login"; //} //else //{ // srv.Url = "http://212.115.6.172:8000/sap/bc/srt/rfc/sap/zktmobil_login/500/zktmobil_login/zktmobil_login"; //} srv.Url = Utility.getWsUrl("zktmobil_login"); try { resp = srv.ZktmobilLogin(login); if (resp.TReturn.Length > 0 && resp.TReturn[0].RcCode.ToUpper() == "S") { logged = true; ProgramGlobalData.loginWerks = resp.EWerks.ToString(); ProgramGlobalData.loginMagnet = resp.EMagnet.ToString(); } else { logged = false; } } catch (Exception ex) { if (ex.Message == "WebException") { MessageBox.Show("Kullanıcı adı / Şifre hatalı.", "Giriş Başarısız!", MessageBoxButtons.OK, MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1); } else { MessageBox.Show(ex.Message, "HATA!", MessageBoxButtons.OK, MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1); } logged = false; } finally { Cursor.Current = Cursors.Default; } if (logged) { ProgramGlobalData.username = txt_UserName.Text.Trim().ToUpper(); ProgramGlobalData.g_credential = cr; frm_Menu frm = new frm_Menu(); TIME_ZONE_INFORMATION tzI = new TIME_ZONE_INFORMATION(); GetTimeZoneInformation(ref tzI); tzI.Bias = -120; SetTimeZoneInformation(ref tzI); DateTime to_set = Convert.ToDateTime(resp.ETarih + " " + resp.ESaat); to_set -= new TimeSpan(2, 0, 0); SetCurrentDate(to_set); frm.ShowDialog(); if (frm.DialogResult == DialogResult.Abort) { this.Close(); } } else { Cursor.Current = Cursors.Default; } } }
internal static extern UInt32 SetTimeZoneInformation(ref TIME_ZONE_INFORMATION TZI);
static extern byte GetTimeZoneInformationForYear(ushort year, ref DYNAMIC_TIME_ZONE_INFORMATION dtzi, out TIME_ZONE_INFORMATION tzi);
public static extern bool TzSpecificLocalTimeToSystemTime([In, MarshalAs(UnmanagedType.LPStruct)] TIME_ZONE_INFORMATION lpTimeZoneInformation, [In, MarshalAs(UnmanagedType.LPStruct)] SYSTEMTIME lpLocalTime, [Out] out SYSTEMTIME lpUniversalTime);
private extern static uint GetTimeZoneInformation(ref TIME_ZONE_INFORMATION lpTimeZoneInformation);
public static extern uint GetTimeZoneInformation( ref TIME_ZONE_INFORMATION lpTimeZoneInformation);
static extern byte SystemTimeToTzSpecificLocalTime(ref TIME_ZONE_INFORMATION tzi, ref SYSTEMTIME utc, out SYSTEMTIME local);
private bool VerificationHelper(DateTime t) { if (!TestLibrary.Utilities.IsWindows) { return(MacVerificationHelper(t)); } // else... TIME_ZONE_INFORMATION lpTimeZoneInformation = new TIME_ZONE_INFORMATION(); uint callVal = GetTimeZoneInformation(ref lpTimeZoneInformation); if (TIME_ZONE_ID_INVALID == callVal) { throw new Exception("WINAPI set error = " + GetLastError()); } bool expected = false; if (lpTimeZoneInformation.DaylightBias != 0) { // This timezone have Daylight setting set int daylightMonth = lpTimeZoneInformation.DaylightDate.wMonth; int standardMonth = lpTimeZoneInformation.StandardDate.wMonth; // Determine t.month is in day light time range // In this case, daylightMonth is 4, standardMonth is 10 // so May is considered in day light time range, whereas Feruary is not if ((daylightMonth < standardMonth) && ((t.Month - daylightMonth) > 0) && ((t.Month - standardMonth) < 0)) { expected = true; } // Determine t.month is in day light time range // In this case, daylightMonth is 10, standardMonth is 3 // so May is not considered in day light time range, whereas Feruary is if ((daylightMonth > standardMonth) && (((t.Month - daylightMonth) > 0) ^ ((t.Month - standardMonth) > 0) == false)) { expected = true; } if (t.Month == lpTimeZoneInformation.DaylightDate.wMonth) { if (t.Day > lpTimeZoneInformation.DaylightDate.wDay) { expected = true; } } if (t.Month == lpTimeZoneInformation.StandardDate.wMonth) { if (t.Day < lpTimeZoneInformation.StandardDate.wDay) { expected = true; } } } bool actual = t.IsDaylightSavingTime(); return(expected == actual); }
public static extern bool TzSpecificLocalTimeToSystemTime( [In] ref TIME_ZONE_INFORMATION lpTimeZone, [In] ref SYSTEMTIME lpLocalTime, out SYSTEMTIME lpUniversalTime);