有人能指出我的所有时区引用的id在TimeZoneInfo.FindTimeZoneById()的完整列表吗?我在任何地方都找不到一个列表,我已经查看了. net文档。
当前回答
我知道这是一个老问题,但微软现在似乎已经通过MSDN提供了这一点。
http://msdn.microsoft.com/en-us/library/gg154758.aspx
其他回答
下面是一个程序及其结果的完整列表。
代码:
using System;
namespace TimeZoneIds
{
class Program
{
static void Main(string[] args)
{
foreach (TimeZoneInfo z in TimeZoneInfo.GetSystemTimeZones())
{
// For a Console App
Console.WriteLine(z.Id + "," + z.BaseUtcOffset + "," + z.StandardName + "," + z.DisplayName + "," + z.DaylightName);
// For any other App
System.Diagnostics.Debug.WriteLine(z.Id + "," + z.BaseUtcOffset + "," + z.StandardName + "," + z.DisplayName + "," + z.DaylightName);
}
}
}
}
结果会随着时间而改变:
时区标识符列表,默认包含在Windows XP和Vista中:查找本地系统上定义的时区
从MSDN
ReadOnlyCollection<TimeZoneInfo> zones = TimeZoneInfo.GetSystemTimeZones();
Console.WriteLine("The local system has the following {0} time zones", zones.Count);
foreach (TimeZoneInfo zone in zones)
Console.WriteLine(zone.Id);
这是c#中的SelectListItem (asp .net)
你可以在后台写代码:
public static List<SelectListItem> GetTimezoneList()
{
try
{
// list of timezone
List<SelectListItem> timezoneList = new List<SelectListItem>();
timezoneList.Add(new SelectListItem() { Value = "", Text = "Select TimeZone...", Selected = false });
var timezoneInfo = TimeZoneInfo.GetSystemTimeZones();
foreach (var item in timezoneInfo)
{
timezoneList.Add(new SelectListItem()
{
Value = item.StandardName, Text = item.DisplayName, Selected = false });
}
return timezoneList;
}
}
catch (Exception e)
{
throw e;
}
}
在前端
@Html.DropDownListFor(s => s.TimeZone, YourbackendServiceName.GetTimezoneList(), new { @class = "form-control input-md" })
这将给你所有的时区DisplayName…即印度标准时间 下拉列表
DateTime dt;
TimeZoneInfo tzf;
tzf = TimeZoneInfo.FindSystemTimeZoneById("TimeZone String");
dt = TimeZoneInfo.ConvertTime(DateTime.Now, tzf);
lbltime.Text = dt.ToString();
推荐文章
- 在EF中更新父实体时如何添加/更新子实体
- ASP。NET身份的默认密码散列器-它是如何工作的,它是安全的?
- 如何写一个JSON文件在c# ?
- 静态隐式运算符
- 不区分大小写列表搜索
- 'throw'和'throw new Exception()'的区别
- 不能在lambda表达式中使用ref或out参数
- c# int到字节[]
- 将WPF组合框绑定到自定义列表
- foreach vs somlist . foreach (){}
- 为什么try{…}最后{…}好;尝试{…} catch{}坏?
- c# 8用多种情况切换表达式,结果相同
- 在没有事件源注册的情况下写入Windows应用程序事件日志
- 并发HashSet<T>在。net框架?
- 从控制器内获得控制器和动作名称?