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

最近新闻内容青海网站seo

最近新闻内容,青海网站seo,软件测试流程及规范,广州建设交易中心官网使用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.mmbaike.com/news/33681.html

相关文章:

  • 怎么做婚恋网站优化设计五年级下册数学答案
  • 引用网站的内容如何做注释网站统计平台
  • 电影网站建设步骤湖南做网站的公司
  • 网站开发实训设计报告湖南seo快速排名
  • 网站建设 报价seo关键词优化排名软件
  • 哪个公司做网站好 知乎扬州seo优化
  • wordpress文章发布添加项目北京网站sem、seo
  • 90后做网站月入万元西安互联网推广公司
  • 谷城网站快速排名seo交流网
  • ie兼容性 网站网站首页推广
  • 牡丹菏泽网站建设阿拉善盟seo
  • 工商企业注册登记网官网北京seo工程师
  • 江门免费建站seo招聘信息
  • 人社部门网站建设中国站长工具
  • 做网站在哪个地方买空间2024年4月新冠疫情结束了吗
  • 中文设计网站济南竞价托管公司
  • php网站开发示例代码自己如何注册网站
  • 备份文件wordpress贺州seo
  • 哈尔滨网站优化如何下载百度官方网站
  • 免费制作动画网站电话百度
  • 手机网站建google网站入口
  • 国外h5制作网站模板链接生成器在线制作
  • 怎么做网站排名优化免费seo推广培训学费
  • 怎么做网站的分类目录bt磁力
  • 新媒体网站建设十大的经典成功案例网络销售怎么才能找到客户
  • 建设网站的相关技术google chrome谷歌浏览器
  • 乐清网站建设网站建设在哪里查关键词排名
  • ftp服务器搭建设置网站信息跨境电商怎么做
  • 微信分销算b2c网站吗seo门户
  • wordpress主题点赞百度词条优化工作