اصلاح daylight saving time ویندوز تا 90 سال بعد
نویسنده: وحید نصیری
تاریخ: ۱۳۹۱/۰۶/۳۱ ۰:۳۱
آدرس: www.dntips.ir
| مطالب | ۳۶۹۴ |
| نویسندگان | ۲۷۶ |
| گروههای مطالب | ۱۰۲۴ |
| نقشههای راه | ۱۱۹ |
| دورهها | ۱۴ |
| اشتراکها | ۱۷۹۱۴ |
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\TimeZoneInformation] [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Time Zones\Iran Standard Time]
Windows Registry Editor Version 5.00 [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Time Zones\Iran Standard Time] "Display"="(GMT+03:30) Tehran" "Dlt"="Iran Daylight Time" "Std"="Iran Standard Time" "MapID"="-1,72" "Index"=dword:000000a0 "TZI"=hex:2e,ff,ff,ff,00,00,00,00,c4,ff,ff,ff,00,00,09,00,04,00,03,00,17,00,3b,\ 00,3b,00,00,00,00,00,03,00,02,00,03,00,17,00,3b,00,3b,00,00,00
using System.Runtime.InteropServices;
namespace TimeZoneInfo.Core
{
[StructLayout(LayoutKind.Sequential)]
public struct TZI
{
public int Bias;
public int StandardBias;
public int DaylightBias;
public SystemTime StandardDate;
public SystemTime DaylightDate;
}
}
using System;
using System.Runtime.InteropServices;
namespace TimeZoneInfo.Core
{
[StructLayoutAttribute(LayoutKind.Sequential)]
public struct SystemTime
{
public short Year;
public short Month;
public short DayOfWeek;
public short Day;
public short Hour;
public short Minute;
public short Second;
public short Milliseconds;
}
}
2C 01 00 00 00 00 00 00 C4 FF FF FF 00 00 0A 00 00 00 05 00 02 00 00 00 00 00 00 00 00 00 04 00 00 00 01 00 02 00 00 00 00 00 00 00
(little-endian) => (big-endian) 2C 01 00 00 => 00 00 01 2C = 300 Bias 00 00 00 00 => 00 00 00 00 = 0 Std Bias C4 FF FF FF => FF FF FF C4 = 4294967236 Dlt Bias ( SYSTEM TIME ) StandardDate 00 00 => 00 00 = Year 0A 00 => 00 0A = Month 00 00 => 00 00 = Day of Week 05 00 => 00 05 = Day 02 00 => 00 02 = Hour 00 00 => 00 00 = Minutes 00 00 => 00 00 = Seconds 00 00 => 00 00 = Milliseconds ( SYSTEM TIME ) DaylightDate 00 00 => 00 00 = Year 04 00 => 00 04 = Month 00 00 => 00 00 = Day of Week 01 00 => 00 01 = Day 02 00 => 00 02 = Hour 00 00 => 00 00 = Minutes 00 00 => 00 00 = Seconds 00 00 => 00 00 = Milliseconds
public static SystemTime ToSystemTime(DateTime time)
{
var result = new SystemTime
{
Year = 0, // سال نسبی وارد میشود نه مطلق
Month = (short)time.Month,
DayOfWeek = (short)time.DayOfWeek,
Hour = (short)time.Hour,
Minute = (short)time.Minute,
Second = (short)time.Second,
Milliseconds = (short)time.Millisecond
};
int weekdayOfMonth = 1; // شماره هفته است نه شماره روز
for (int dd = time.Day; dd > 7; dd -= 7)
weekdayOfMonth++;
result.Day = (short)weekdayOfMonth;
return result;
}
using System;
using System.Runtime.InteropServices;
namespace TimeZoneInfo.Core
{
public static class ByteUtils
{
public static Byte[] SerializeByteArray<T>(T msg) where T : struct
{
int objsize = Marshal.SizeOf(typeof(T));
Byte[] ret = new Byte[objsize];
IntPtr buff = Marshal.AllocHGlobal(objsize);
Marshal.StructureToPtr(msg, buff, true);
Marshal.Copy(buff, ret, 0, objsize);
Marshal.FreeHGlobal(buff);
return ret;
}
}
}
var iranStandardTime = TimeZoneInfo.GetSystemTimeZones()
.FirstOrDefault(timeZoneInfo =>
timeZoneInfo.StandardName.Contains("Iran",
StringComparison.OrdinalIgnoreCase));
Console.WriteLine(iranStandardTime.BaseUtcOffset); // 03:30:00