我沒有使用任何Java腳本。 我的代碼是:錯誤的時區信息的C#代碼
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
System.Collections.ObjectModel.ReadOnlyCollection<TimeZoneInfo> TimeZoneColl = TimeZoneInfo.GetSystemTimeZones();
DropDownList2.DataSource = TimeZoneColl;
DropDownList2.DataBind();
}
}
protected void Button1_Click(object sender, EventArgs e)
{
string d = DateTime.Now.ToString();
string sel =DropDownList2.SelectedValue;
Label1.Text = d;
TimeZoneInfo tst = TimeZoneInfo.FindSystemTimeZoneById("Norway Standard Time");
Label1.Text = tst.ToString();
//TimeZoneInfo timeinfo = TimeZoneInfo.FindSystemTimeZoneById(sel);
//Label3.Text =timeinfo.ToString();
try
{
DateTime tstTime = TimeZoneInfo.ConvertTime(DateTime.Now, TimeZoneInfo.Local, tst);
Label3.Text = tstTime.ToLongTimeString();
}
catch (Exception E)
{
Console.WriteLine("Error" + E);
}
}
但通過ID發現getzone區選擇錯誤。 這裏的區域可以選擇格式(東京標準時間) 但我想從下拉列表中選擇它。 所以下拉列表中包含其他格式。
如何將區域綁定到下拉列表?什麼'TimeZoneInfo'屬性分配給值和顯示文本? – mmix 2011-05-05 09:28:33
你會得到哪些例外? – 2011-05-05 09:29:17
綁定工作正常。但錯誤在TimeZoneInfo tst = TimeZoneInfo.FindSystemTimeZoneById(「挪威標準時間」);這裏在參數中我想通過下拉列表選擇它。像TimeZoneInfo tst = TimeZoneInfo.FindSystemTimeZoneById(dropdown.selecteditem); – Manish 2011-05-05 09:31:42