开发者

Convert local time to UTC in .NET framework 3.0

I develop an app. in c#, I should translate local time to UTC, the local time is in time zone that who that use in my app. enters. I must use in .NET framework 3.0, so can't use the TimeZoneInfo obj开发者_开发问答ect.

Does anyone has an idia how can I do it?

Should use in TimeZone Object?

Thanks

Maybe I can't do it?


Now I see the problem. Use the following method instead: TimeZone.ToUniversalTime


every time I save time in a database I ALWAYS save in UTC time

myEntity.CreateDate = DateTime.UtcNow;

Now, in 3.0 or less

use this file

http://pastebin.com/w20NRkuP

it contains a helper so you can list all Timezones and have their values. Add it to your db or use on-the-fly.

Fill up a dropdown and ask user to choose it's own TimeZone, then, just add the Minutes to your saved UTC Date.

for example:

<asp:DropDownList ID="myDropDown" runat="server" />

then

myDropDown.DataSource = Helper.ListAllTimeZones();
myDropDown.DataValueField = "UtcOffsetMinutes";
myDropDown.DataTextField = "DisplayName";

myDropDown.DataBind();

when saving user preferences:

User.OffSet = (int)myDropDown.SelectedValue;

hope it helps


for example, sweetie.com does this:

Convert local time to UTC in .NET framework 3.0

just request the timezone to the user and save all in UTC time, then just add/subtract the timezone.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜