时区转换问题 [英] Time Zone Conversion Issue

查看:84
本文介绍了时区转换问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

在我的程序中,我正在处理2 DateTime,这是客户在特定机场的起飞时间和到达时间.这些DateTime数据将由旅行社通过Web服务提供,其中将仅提供以下数据:

(出发部分)
-日期1
-时间1
-国家/地区代码1(ISO 3166)
(到达部分)
-日期2
-时间2
-国家/地区代码2(ISO 3166)

DateTime 2必须转换为没有提供TimeZone或TimeZoneID信息的DateTime 1.没有手动将所有国家代码及其对应的TimeZoneID存储在数据库中的方法,是否有任何可能的方法? TimeZoneInfo中是否有任何功能可以对此进行存档?还是有什么方法可以仅使用国家/地区代码来检索相关的时区?

PS:对不起,我的语法不好.

Hi All,

In my program, i was dealing with 2 DateTime which is the departure time and arrival time of customer at specific airport. These DateTime data will be provided by a travel agent through web service where as there will be only the following data provided:

(Departure Part)
- Date 1
- Time 1
- Country Code 1 (ISO 3166)
(Arrival Part)
- Date 2
- Time 2
- Country Code 2 (ISO 3166)

DateTime 2 have to convert to DateTime 1 where there is no TimeZone or TimeZoneID info provided. Is there any possible way to do this without manually storing all the country code and their corresponding TimeZoneID in database? Is there any function in TimeZoneInfo that can archive this? Or is there any way to retrieve the related timezone by just using the country code?

P.S: Sorry for my bad grammar.

推荐答案

您可以存储GMT,然后让客户端应用将其适应当地时间.
You could just store GMT, and let the client app adapt it to local time.


尝试查看TimeZoneInfo.FindSystemTimeZoneById: MSDN [ ^ ]
Try looking at TimeZoneInfo.FindSystemTimeZoneById: MSDN[^]


将其转换为以下内容:

Convert it something like this:

DateTime fromDB = new DateTime(1,1,2011,12,0,0);
fromDB.Kind = DateTimeKind.Utc;
DateTime converted = fromDB.DateToLocalTime();


这篇关于时区转换问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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