datetime - UTC 到本地时区之间的 C# DateTime 转换
问题描述
能够使用以下代码将本地日期时间转换为 UTC。
a. TimeZoneInfo.ConvertTimeToUtc(dateTimeValue, TimeZoneInfo.FindSystemTimeZoneById(localTimeZone));b. TimeZoneInfo.ConvertTime(dateTimeValue, TimeZoneInfo.FindSystemTimeZoneById(localTimeZone), TimeZoneInfo.FindSystemTimeZoneById("UTC");
并使用以下代码将 UTC 转换为本地。
a. TimeZoneInfo.ConvertTimeFromUtc(dateTimeValue, TimeZoneInfo.FindSystemTimeZoneById(localTimeZone));
b. TimeZoneInfo.ConvertTime(dateTimeValue, TimeZoneInfo.FindSystemTimeZoneById("UTC"), TimeZoneInfo.FindSystemTimeZoneById(localTimeZone));
当应用程序在 Visual Studio(调试模式)中运行时,它工作正常。但是在美国服务器(东部时区)托管应用程序并从印度浏览应用程序后,从 UTC 到本地的时间转换不起作用。这里 localTimeZone 是“印度标准时间”(本地时区从客户端机器获取并从日期时间转换发送到服务器。)
示例:
IST DateTime: 12/10/2018 18:37
UTC DateTime: 2018-12-10 06:05 (IST 到 UTC)
转换的日期时间: 12/11/2018 05:07(UTC 到 IST)
如果我们将本地时区设置为“东部时区”,则转换正确。
任何人都可以为这种情况提供解决方案。
解决方案
推荐阅读
- ansible - 使用 Ansible 删除配置文件中的确切行块
- rest - 如何使用外部 api 休息?
- c++ - 如何在 Ubuntu 中将内容从一个文件传输到另一个文件。?
- excel - How to insert a point in a txt file?
- python - Flask-sqlalchmey 行更新反映在 sqlite DB 中
- scala - SCALA 和弹性搜索:将符号添加到类路径(Databricks)
- cleartool - rmstream 的 CCRC 命令
- python-3.x - 如何获取键的索引?
- angular - How to make observable wait for the previous observable to complete
- python - 有没有一种简单的方法可以在 python 的列表中输出一个列表?像这样 [[0,1], [2,3]]