请一些身体告诉我如何将印度时间转换为英国时间英国夏令时和格林威治标准时间格林威治标准时间 [英] pls Some Body Tell me how to convert indian standrad time to uk time uk time somties BST British Summer Time and somtmes GMT Greenwich Mean Time

查看:68
本文介绍了请一些身体告诉我如何将印度时间转换为英国时间英国夏令时和格林威治标准时间格林威治标准时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

public DateTime timezone()
      {

          string date = "2009-02-25 16:13:00Z";
          // Local .NET timeZone.
          DateTime localDateTime = DateTime.Parse(date);
          DateTime utcDateTime = localDateTime.ToUniversalTime();

          // ID from: 
          // "HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Time Zone"
          // See http://msdn.microsoft.com/en-us/library/system.timezoneinfo.id.aspx
          string ukTimeZoneKey = "British Summer Time";
          TimeZoneInfo ukTimeZone = TimeZoneInfo.FindSystemTimeZoneById(ukTimeZoneKey);
          DateTime ukDateTime = TimeZoneInfo.ConvertTimeFromUtc(utcDateTime, ukTimeZone );

          return ukDateTime ;


      }







这有时不起作用bcz这是在英国夏令时间,有时它是在格林威治标准时间,我没有在我的电脑中注册

格林威治标准时间和英国夏令时





伦敦多年来的时间变化



夏令时(DST)的变化不一定发生在每年同一天。



时区变更:

年度日期&时间缩短时间变更

2013年太阳报,3月31日,格林威治标准时间01:00→BST +1小时(夏令时开始)

太阳,10月27日,02:00 BST→GMT -1小时(DST结束)

2014年太阳报,3月30日,格林威治标准时间01:00→BST +1小时(夏令时开始)

Sun,10月26日,02:00 BST→GMT -1小时(DST结束)

2015年太阳报,3月29日,格林威治标准时间01:00→BST +1小时(夏令时开始)

太阳报,10月25日, 02:00 BST→GMT -1小时(夏令时结束)

2016年太阳报,3月27日,格林威治标准时间01:00→BST +1小时(夏令时开始)

太阳, 10月30日,02:00 BST→GMT -1小时(夏令时结束)

2017年太阳,3月26日,格林威治标准时间01:00→BST +1小时(夏令时开始)

太阳,10月29日,02:00 BST→GMT -1小时(夏令时结束)











http://www.timeanddate.com/time/zone/uk/london [ ^ ]这包含时间x32更改



请帮我解决




this will not work bcz sometimes it is in British Summer Time and sometimes it is in Greenwich Mean Time and i didn't have registry in my pc of
Greenwich Mean Time and British Summer Time


Time Changes in London over the years

Daylight Saving Time (DST) changes do not necessarily occur on the same date every year.

Time zone changes for:
Year Date & Time Abbreviation Time Change
2013 Sun, 31 Mar, 01:00 GMT → BST +1 hour (DST start)
Sun, 27 Oct, 02:00 BST → GMT -1 hour (DST end)
2014 Sun, 30 Mar, 01:00 GMT → BST +1 hour (DST start)
Sun, 26 Oct, 02:00 BST → GMT -1 hour (DST end)
2015 Sun, 29 Mar, 01:00 GMT → BST +1 hour (DST start)
Sun, 25 Oct, 02:00 BST → GMT -1 hour (DST end)
2016 Sun, 27 Mar, 01:00 GMT → BST +1 hour (DST start)
Sun, 30 Oct, 02:00 BST → GMT -1 hour (DST end)
2017 Sun, 26 Mar, 01:00 GMT → BST +1 hour (DST start)
Sun, 29 Oct, 02:00 BST → GMT -1 hour (DST end)





http://www.timeanddate.com/time/zone/uk/london[^] this contains time xone changes

pls help me out

推荐答案

从GMT到BST的变化以及在固定点发生的变化在日历中,在3月和10月的最后一个星期日。转换规则在每个操作系统的每台计算机中设置。只需要以本地格式请求时间,您就可以获得一年中任何时间的正确时间。您可以通过设置环境变量来调整所需的时区,并使用标准库来进行转换。如果你想手动完成,那么你需要了解时区注册表项的结构,如下所示:



Changes from GMT to BST and back occur at fixed points in the calendar, last Sundays of March and October. The rules for converting are set in every computer of every operating system. You get the correct time for any time of the year just by requesting the time in local format. You can adjust the timezone required by setting environment variables, and using the standard libraries to do the conversion. If you want to do it manually then you need to unsderstand the structure of the registry entries for timezones as follows:

Retrieving Time-Zone Information

Article ID: Q115231  
The information in this article applies to: 
Microsoft Win32 Application Programming Interface (API) included with: 


    - Microsoft Windows NT versions 3.1, 3.5, and 3.51
    - Microsoft Windows 95 version 4.0


In Windows NT, version 3.1, the time-zone strings are compiled into a resource that is linked into the CONTROL.EXE file. For Windows NT, version 3.5 and later and Windows 95, the time-zone strings have been moved into the registry. 

In Windows NT, the time-zone strings are located in the key: 


   HKEY_LOCAL_MACHINE\SOFTWARE\
      Microsoft\
      Windows NT\
      CurrentVersion\
      Time Zones.


In Windows 95, the time-zone strings are located in the key: 

   HKEY_LOCAL_MACHINE\SOFTWARE\
      Microsoft\
      Windows\
      CurrentVersion\
      Time Zones.


For each time zone, the registry key TZI is formatted as follows: 

   LONG       Bias;
   LONG       StandardBias;
   LONG       DaylightBias;
   SYSTEMTIME StandardDate;
   SYSTEMTIME DaylightDate;


You can use this information to fill out a TIME_ZONE_INFORMATION 
structure, which is used when calling SetTimeZoneInformation(). 
 
0xffffffc4
00000000
0xffffffc4
Year Month dow  day  hour min  sec  msec
0000 000A 0000 0005 0003 0000 0000 0000

0000 0003 0000 0005 0002 0000 0000 0000


--------------------------------------------------------------------------------

 

TIME_ZONE_INFORMATION
The TIME_ZONE_INFORMATION structure specifies information 
specific to the time zone. 

typedef struct _TIME_ZONE_INFORMATION { // tzi 
    LONG       Bias; 
    WCHAR      StandardName[ 32 ]; 
    SYSTEMTIME StandardDate; 
    LONG       StandardBias; 
    WCHAR      DaylightName[ 32 ]; 
    SYSTEMTIME DaylightDate; 
    LONG       DaylightBias; 
} TIME_ZONE_INFORMATION; 
 
Members

Bias 
	Specifies the current bias, in minutes, for local time 
	translation	on this computer. The bias is the difference, in 
	minutes, between Coordinated Universal Time (UTC) and local 
	time. All translations between UTC and local time are based on 
	the following formula: 

		UTC = local time + bias 
 
This member is required. 

StandardName 
	Specifies a null-terminated string associated with standard 
	time on this operating system. For example, this parameter 
	could contain "EST" to indicate Eastern Standard Time. This 
	string is not used by the operating system, so anything stored 
	there by using the SetTimeZoneInformation function is returned 
	unchanged by the GetTimeZoneInformation function. This string 
	can be empty. 

StandardDate 
	Specifies a SYSTEMTIME structure that contains a date and local 
	time when the transition from daylight time to standard time 
	occurs on this operating system. If this date is not specified, 
	the wMonth member in the SYSTEMTIME structure must be zero. If 
	this date is specified, the DaylightDate value in the 
	TIME_ZONE_INFORMATION structure must also be specified. 
	This member supports two date formats. Absolute format 
	specifies an exact date and time when standard time begins. In 
	this form, the wYear, wMonth, wDay, wHour, wMinute, wSecond, 
	and wMilliseconds members of the SYSTEMTIME structure are used 
	to specify an exact date. 

	Day-in-month format is specified by setting the wYear member 
	to zero, setting the wDayOfWeek member to an appropriate 
	weekday, and using a wDay value in the range 1 through 5 to 
	select the correct day in the month. Using this notation, the 
	first Sunday in April can be specified, as can the last 
	Thursday in October (5 is equal to "the last"). 

StandardBias 
	Specifies a bias value to be used during local time 
	translations that occur during standard time. This member is 
	ignored if a value for the StandardDate member is not supplied.
	This value is added to the value of the Bias member to form 
	the bias used during standard time. In most time zones, the 
	value of this member is zero. 

DaylightName 
	Specifies a null-terminated string associated with daylight 
	time on this operating system. For example, this parameter 
	could contain "PDT" to indicate Pacific Daylight Time. This 
	string is not used by the operating system, so anything stored 
	there by using the SetTimeZoneInformation function is returned 
	unchanged by the GetTimeZoneInformation function. This string 
	can be empty. 

DaylightDate 
	Specifies a SYSTEMTIME structure that contains a date and 
	local time when the transition from standard time to daylight 
	time occurs on this operating system. If this date is not 
	specified, the wMonth member in the SYSTEMTIME structure must 
	be zero. If this date is specified, the StandardDate value in 
	the TIME_ZONE_INFORMATION structure must also be specified. 
	This member supports the absolute and day-in-month time formats 
	described for the StandardDate member. 

DaylightBias 
	Specifies a bias value to be used during local time translations 
	that occur during daylight time. This member is ignored if a 
	value for the DaylightDate member is not supplied. 
	This value is added to the value of the Bias member to form the 
	bias used during daylight time. In most time zones, the value of 
	this member is – 60. 


See Also
	Time Overview, 
	Time Structures, 
	GetTimeZoneInformation, 
	SetTimeZoneInformation, 
	SYSTEMTIME 


您需要使用的时区ID是: GMT标准时间



TimeZoneInfo [ ^ ]应自动处理夏令时,因此您无需担心获取不同日期的不同时区。

The time zone ID you need to use is: GMT Standard Time

The TimeZoneInfo class[^] should automatically handle daylight saving time, so you don't need to worry about getting different time-zones for different dates.
string date = "2009-07-25 16:13:00Z";
DateTime localDateTime = DateTime.Parse(date);
DateTime utcDateTime = localDateTime.ToUniversalTime();
 
string ukTimeZoneKey = "GMT Standard Time";
TimeZoneInfo ukTimeZone = TimeZoneInfo.FindSystemTimeZoneById(ukTimeZoneKey);
DateTime ukDateTime = TimeZoneInfo.ConvertTimeFromUtc(utcDateTime, ukTimeZone);





由于您在多个时间内处理日期 - 区域,最好使用 DateTimeOffset class [ ^ ]而不是 DateTime 类。



Since you're working with dates in multiple time-zones, it would probably be better to use the DateTimeOffset class[^] instead of the DateTime class.

string date = "2009-07-25 16:13:00Z";
DateTimeOffset localDateTime = DateTimeOffset.Parse(date);
 
string ukTimeZoneKey = "GMT Standard Time";
TimeZoneInfo ukTimeZone = TimeZoneInfo.FindSystemTimeZoneById(ukTimeZoneKey);
DateTimeOffset ukDateTime = TimeZoneInfo.ConvertTime(localDateTime, ukTimeZone);


这篇关于请一些身体告诉我如何将印度时间转换为英国时间英国夏令时和格林威治标准时间格林威治标准时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆