Time zone in Asp.net

Source: Internet
Author: User

First, several applications of date-time conversion in Asp.net:

1.<ASP: boundcolumn datafield = "JoinTime" DATAFORMATSTRING = "{0: yyyy-MM-dd}"> <itemstyle width = "18%"> </ITEMSTYLE> </ASP: BOUNDCOLUMN>
2.E. Item. Cell [0]. Text = Convert. ToDateTime (e. Item. Cell [0]. Text). to1_datestring ();
3.String. Format ("yyyy-MM-dd", yourDateTime );
4.Convert. ToDateTime ("2005-8-23"). ToString ("yyMMdd", System. Globalization. DateTimeFormatInfo. InvariantInfo );
5.<Asp: BoundColumn DataField = "receipt time" HeaderText = "receipt time"
DataFormatString = "{0: yyyy-mm-dd}"> </asp: BoundColumn>
6.DateTime. Now. ToString ("yyyyMMddhhmmss ")
7.DateTime. Now. ToString ("yyyy/MM/dd hh: mm: ss ")
8. show only the year and month 
DataBinder. Eval (Container. DataItem, "starttime", "{0: yyyy-M }")
9.<Asp: BoundColumn DataField = "receipt time" HeaderText = "receipt time"
DataFormatString = "{0: yyyy-MM-dd HH24: mm: ss}"> </asp: BoundColumn>

 

Second, the list of valid time zones in the system:

1. Obtain the time zone list based on the local time:

DateTimeOffset chinaDate = DateTimeOffset. Now; // current local time
Response. Write (chinaDate. ToString () + "<br/> ");

ReadOnlyCollection <TimeZoneInfo> zones = TimeZoneInfo. GetSystemTimeZones (); // list of Time Zone identifiers in the system
Foreach (TimeZoneInfo timeZoneInfo in zones)
{

// Obtain the Greenwich mean time through the local time, and obtain the names of different time zone IDs and their corresponding time through the standard time
DateTimeOffset easternDate = TimeZoneInfo. ConvertTime (chinaDate. UtcDateTime,
TimeZoneInfo. FindSystemTimeZoneById (timeZoneInfo. Id ));
Response. Write (timeZoneInfo. Id + ": & nbsp ;"
+ EasternDate. ToString () + "<br/> ");
}

The result is as follows:

14:33:12 +
Greenwich Standard Time: 6:33:12 +
GMT Standard Time: 7:33:12 +
W. Central Africa Standard Time: 7:33:12 +
Romance Standard Time: 8:33:12 +
Central European Standard Time: 8:33:12 +
Central Europe Standard Time: 8:33:12 +
W. Europe Standard Time: 8:33:12 +
South Africa Standard Time: 8:33:12 +
E. Europe Standard Time: 9:33:12 +
Egypt Standard Time: 9:33:12 +
Israel Standard Time: 8:33:12 +
FLE Standard Time: 9:33:12 +
GTB Standard Time: 9:33:12 +
E. Africa Standard Time: 9:33:12 +
Arabic Standard Time: 10:33:12 +
Arab Standard Time: 9:33:12 +
Russian Standard Time: 10:33:12 +
Iran Standard Time: 11:03:12 +
Caucasus Standard Time: 11:33:12 +
Arabian Standard Time: 10:33:12 +
Afghanistan Standard Time: 11:03:12 +
West Asia Standard Time: 11:33:12 +
Ekaterinburg Standard Time: 12:33:12 +
India Standard Time: 12:03:12 +
Nepal Standard Time: 12:18:12 +
Sri Lanka Standard Time: 12:33:12 +
N. Central Asia Standard Time: 13:33:12 +
Central Asia Standard Time: 12:33:12 +
Myanmar Standard Time: 13:03:12 +
North Asia Standard Time: 14:33:12 +
SE Asia Standard Time: 13:33:12 +
North Asia East Standard Time: 15:33:12 +
China Standard Time: 14:33:12 +
Taipei Standard Time: 14:33:12 +
Singapore Standard Time: 14:33:12 +
W. Australia Standard Time: 14:33:12 +
Tokyo Standard Time: 15:33:12 +
Korea Standard Time: 15:33:12 +
Yakutsk Standard Time: 16:33:12 +
AUS Central Standard Time: 16:03:12 +
Cen. Australia Standard Time: 16:03:12 +
West Pacific Standard Time: 16:33:12 +
AUS Eastern Standard Time: 16:33:12 +
E. Australia Standard Time: 16:33:12 +
Invalid Vostok Standard Time: 17:33:12 +
Tasmania Standard Time: 16:33:12 +
Central Pacific Standard Time: 17:33:12 +
New Zealand Standard Time: 18:33:12 +
Fiji Standard Time: 18:33:12 +
Tonga Standard Time: 19:33:12 +
Azores Standard Time: 6:33:12 +
Cape Verde Standard Time: 5:33:12 +
Mid-Atlantic Standard Time: 5:33:12 +
E. South America Standard Time: 3:33:12 +
SA Eastern Standard Time: 3:33:12 +
Greenland Standard Time: 4:33:12 +
Newfoundland Standard Time: 4:03:12 +
SA Western Standard Time: 2:33:12 +
Pacific SA Standard Time: 2:33:12 +
Atlanta Standard Time: 3:33:12 +
Eastern Standard Time: 2:33:12 +
US Eastern Standard Time: 1:33:12 +
SA Pacific Standard Time: 1:33:12 +
Central America Standard Time: 0:33:12 +
Central Standard Time: 1:33:12 +
Canada Central Standard Time: 0:33:12 +
Mexico Standard Time: 1:33:12 +
US Mountain Standard Time: 23:33:12 +
Mountain Standard Time: 0:33:12 +
Mexico Standard Time 2: 0:33:12 +
Pacific Standard Time: 23:33:12 +
Alaskan Standard Time: 22:33:12 +
Hawaiian Standard Time: 20:33:12 +
Samoa Standard Time: 19:33:12 +
Dateline Standard Time: 18:33:12 +

 

Second, get the client Time Zone offset (javascript ):
Var zone = new Date (). getTimezoneOffset ()/60 *-1;

 

Finally, get the time that should be correctly displayed on the client:

// ServerZoneID is the ID of the Time zone where the database is located, for example, "Eastern Standard Time" in the list above"

DateTimeOffset serverDateTime = TimeZoneInfo. ConvertTime (
DatabaseDateTime, TimeZoneInfo. FindSystemTimeZoneById (serverZoneID ));

// Zone indicates the client Time zone offset.

ServerDateTime. UtcDateTime. AddHours (zone );

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.