C# 3.0 在.Net 3.0中将日期时间从UTC转换为EST

C# 3.0 在.Net 3.0中将日期时间从UTC转换为EST,c#-3.0,timezone,C# 3.0,Timezone,我正在使用.Net 3.0,我想将日期时间值从UTC转换为EST/EDT(也需要合并夏令时) 我知道,在TimeZoneInfo类的帮助下,使用.NET3.5可以直接实现这一点。我不想使用时区。CurrentTimeZone,因为我想将此值转换为EST/EDT,而不考虑本地计算机的时区。不幸的是,切换到3.5不是一个选项。互联网上的搜索显示了使用系统注册表和其他东西的选项 有没有更简单的方法? 有谁能告诉我正确的方向,让我知道实现这一点的方法吗?以下函数确定特定的DateTime对象是否代表东部

我正在使用.Net 3.0,我想将日期时间值从UTC转换为EST/EDT(也需要合并夏令时)

我知道,在
TimeZoneInfo类的帮助下,使用.NET3.5可以直接实现这一点。我不想使用
时区。CurrentTimeZone
,因为我想将此值转换为EST/EDT,而不考虑本地计算机的时区。不幸的是,切换到3.5不是一个选项。互联网上的搜索显示了使用系统注册表和其他东西的选项

有没有更简单的方法?
有谁能告诉我正确的方向,让我知道实现这一点的方法吗?

以下函数确定特定的DateTime对象是否代表东部时区的夏令时

public static bool IsEasternDaylightTime(DateTime dt){
        // Find out whether it's Daylight Saving Time
        dt=dt.AddHours(-5); // Convert to Eastern Standard Time
        if(dt.Year<=2006){
            // 2006 and earlier
            if(dt.Month<=3 || dt.Month>=11){
                // Standard Time
                return false;
            } else if(dt.Month>=5 && dt.Month<=9){
                // Daylight Time
                return true;
            } else if(dt.Month==4){
                // find the first Sunday of April
                int firstSunday=1;
                while(new DateTime(dt.Year,dt.Month,firstSunday).DayOfWeek!= DayOfWeek.Sunday){
                    firstSunday++;
                }
                if(dt.Day<firstSunday)
                    return false;
                else if(dt.Day>firstSunday)
                    return true;
                else {
                    // DST begins at 2AM
                    if(dt.Hour<2)
                        return false; // Standard Time
                    else if(dt.Hour>=3)
                        return true; // Daylight Time
                    else
                        return false; // Ambiguous Time
                }
            } else {
                // find the last Sunday of October
                int lastSunday=1;
                for(int i=1;i<=31;i++){
                    if(new DateTime(dt.Year,dt.Month,i).DayOfWeek== DayOfWeek.Sunday){
                        lastSunday=i;
                    }
                }
                if(dt.Day<lastSunday)
                    return true;
                else if(dt.Day>lastSunday)
                    return false;
                else {
                    // DST ends at 2AM
                    if(dt.Hour<1)
                        return true; // Daylight Time
                    else if(dt.Hour>=2)
                        return false; // Standard Time
                    else
                        return false; // Standard Time
                }
            }
        } else {
            // 2007 and later
            if(dt.Month<=2 || dt.Month>=12){
                // Standard Time
                return false;
            } else if(dt.Month>=4 && dt.Month<=10){
                // Daylight Time
                return true;
            } else if(dt.Month==3){
                // find the second Sunday of March
                int sundays=0;
                int lastSunday=1;
                for(int i=1;i<=31;i++){
                    if(new DateTime(dt.Year,dt.Month,i).DayOfWeek== DayOfWeek.Sunday){
                        lastSunday=i;
                        sundays++;
                        if(sundays==2)break;
                    }
                }
                if(dt.Day<lastSunday)
                    return false;
                else if(dt.Day>lastSunday)
                    return true;
                else {
                    // DST begins at 2AM
                    if(dt.Hour<2)
                        return false; // Standard Time
                    else if(dt.Hour>=3)
                        return true; // Daylight Time
                    else
                        return false; // Ambiguous Time
                }
            } else {
                // find the first Sunday of November
                int firstSunday=1;
                while(new DateTime(dt.Year,dt.Month,firstSunday).DayOfWeek!= DayOfWeek.Sunday){
                    firstSunday++;
                }
                if(dt.Day<firstSunday)
                    return true;
                else if(dt.Day>firstSunday)
                    return false;
                else {
                    // DST ends at 2AM
                    if(dt.Hour<1)
                        return true; // Daylight Time
                    else if(dt.Hour>=2)
                        return false; // Standard Time
                    else
                        return false; // Standard Time
                }
            }
        }
    }

谢谢你的回复!这很有帮助。
 // dateTime is assumed to be in UTC, not local time
 bool dst=IsEasternDaylightTime(dateTime);
 if(dst)
     dateTime=dateTime.AddHours(-4);
 else
     dateTime=dateTime.AddHours(-5);