当前位置: 首页 > news >正文

网站建设制作博走网店运营培训

网站建设制作博走,网店运营培训,代理公司英文,奉贤网站开发使用SetDynamicTimeZoneInformation设置时区返回false&#xff0c;设置失败。 使用PowerShell设置Set-TimeZone成功。 /// <summary> /// 设置本地时区 /// 参数取值"China Standard Time"&#xff0c;即可设置为中国时区 /// </summary> /// <param …

使用SetDynamicTimeZoneInformation设置时区返回false,设置失败。

使用PowerShell设置Set-TimeZone成功。

/// <summary>
/// 设置本地时区
/// 参数取值"China Standard Time",即可设置为中国时区
/// </summary>
/// <param name="timeZoneId"></param>
/// <returns></returns>
public static bool SetLocalTimeZone(string timeZoneId)
{var dynamicTimeZoneInformation = ConvertDynamicTimeZoneInformation(timeZoneId);bool success;// 检测当前系统是否为旧系统if (IsOldOsVersion()){var tzi = ConvertTimeZoneInformation(dynamicTimeZoneInformation);success = SetTimeZoneInformation(ref tzi);}else{success = SetDynamicTimeZoneInformation(ref dynamicTimeZoneInformation);}if (success){TimeZoneInfo.ClearCachedData(); // 清除缓存}else{success = SetTimeZoneByPowerShell(dynamicTimeZoneInformation.timeZoneKeyName);}return success;
}/// <summary>
/// 根据时区名获取对应的DynamicTimeZoneInformation
/// </summary>
/// <param name="timeZoneName"></param>
/// <returns></returns>
private static DynamicTimeZoneInformation ConvertDynamicTimeZoneInformation(string timeZoneName)
{var timeZoneInfo = TimeZoneInfo.FindSystemTimeZoneById(timeZoneName);var info = new DynamicTimeZoneInformation{standardName = timeZoneInfo.StandardName,standardDate = new SystemTime(),daylightName = timeZoneInfo.DaylightName,daylightDate = new SystemTime(),timeZoneKeyName = timeZoneInfo.Id,dynamicDaylightTimeDisabled = false,bias = -Convert.ToInt32(timeZoneInfo.BaseUtcOffset.TotalMinutes)};return info;
}/// <summary>
/// 判断Windows系统是否为旧版本
/// </summary>
/// <returns></returns>
public static bool IsOldOsVersion()
{var os = Environment.OSVersion;return os.Platform != PlatformID.Win32NT || os.Version.Major < 6;
}/// <summary>
/// 将DynamicTimeZoneInformation转换为TimeZoneInformation
/// </summary>
/// <param name="info"></param>
/// <returns></returns>
private static TimeZoneInformation ConvertTimeZoneInformation(DynamicTimeZoneInformation info)
{return new TimeZoneInformation{bias = info.bias,standardName = info.standardName,standardDate = info.standardDate,standardBias = info.standardBias,daylightName = info.daylightName,daylightDate = info.daylightDate,daylightBias = info.daylightBias};
}// 针对于旧Windows系统,如Windows XP
[DllImport("kernel32.dll", CharSet = CharSet.Auto)]
private static extern int GetTimeZoneInformation(ref TimeZoneInformation lpTimeZoneInformation);[DllImport("kernel32.dll", CharSet = CharSet.Auto)]
private static extern bool SetTimeZoneInformation(ref TimeZoneInformation lpTimeZoneInformation);//针对于新Windows系统,如Windows 7,Windows 8, Windows10
[DllImport("kernel32.dll", CharSet = CharSet.Auto)]
private static extern int GetDynamicTimeZoneInformation(ref DynamicTimeZoneInformation lpDynamicTimeZoneInformation);[DllImport("kernel32.dll", CharSet = CharSet.Auto)]
private static extern bool SetDynamicTimeZoneInformation(ref DynamicTimeZoneInformation lpDynamicTimeZoneInformation);/// <summary>
/// 通过PowerShell设置时区
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public static bool SetTimeZoneByPowerShell(string id)
{using var powerShell = PowerShell.Create();try{//通过PowerShell设置时区powerShell.AddCommand("Set-TimeZone").AddParameter("Id", id);powerShell.Invoke();}catch (Exception){return false;}return true;}
http://www.hkea.cn/news/932724/

相关文章:

  • 外贸营销型网站建设今日最新重大新闻
  • 个性化定制网站长春网络推广优化
  • 合肥庐阳区疫情最新消息seo优化首页
  • h5网站制作接单最新中高风险地区名单
  • 北京市住房城乡建设委网站公司怎么在网上推广
  • 网站建设首页怎样插入视频百度指数在线查询小程序
  • 青州网站制作哪家好aso优化哪家好
  • wordpress做网站优点郑州网站seo优化
  • 宝安做棋牌网站建设找哪家公司好湖南长沙疫情最新消息
  • 四川专业网站建设中国十大企业培训机构排名
  • 怎么切页面做网站灰色词首页排名接单
  • 网站右侧浮动广告代码百度推广代理公司广州
  • 固原建站公司旺道seo推广系统怎么收费
  • 适合做外链的网站海外广告联盟平台推广
  • 建筑模板规格型号郑州厉害的seo顾问
  • ppt做书模板下载网站有哪些内容国际婚恋网站排名
  • 上海网站建设内容更新网络营销策划目的
  • 重庆市建设信息网站关键词查询网
  • 做哪种网站流量大怎么打广告宣传自己的产品
  • 免费表白网站制作seo网络优化推广
  • 网站建设中可能升级中国科技新闻网
  • 网站制作内容文案网站如何快速被百度收录
  • 淘宝淘宝网页版登录入口免费seo公司
  • 竹溪县县建设局网站短视频营销
  • 好的网站有哪些搜索引擎seo是什么意思
  • 做音乐网站赚钱吗做小程序的公司
  • 坪地网站建设域名流量查询工具
  • 网站建设部署万能推广app
  • 网站的重要性怎么做个网站
  • 做网站的经验百度旗下有哪些app