[英].NET Core Replacement for ConvertTimeToUtc?
What happened to ConvertTimeToUtc in .NET Core? .NET Core中的ConvertTimeToUtc发生了什么变化? I know it's not there anymore, but has it been replaced by anything else?
我知道它不再存在了,但它被其他任何东西取代了吗? This is how I used to take a clients Date and Time input, and then convert it to UTC to store in database:
这就是我以前用来获取客户端日期和时间输入,然后将其转换为UTC以存储在数据库中的方式:
var timeZoneInfo=TimeZoneInfo.FindSystemTimeZoneById(viewModel.EventTimeZone);
var completeStartDate=TimeZoneInfo.ConvertTimeToUtc(viewModel.StartDate,timeZoneInfo);
This has worked great, until .NET Core. 这非常有效,直到.NET Core。 Any current examples I can find all seem to be using 'ConvertTime', but they are going from UTC to local, which is the opposite of what I am going for here.
我可以找到的任何当前示例似乎都使用'ConvertTime',但它们从UTC到本地,这与我在这里的目的相反。 So can anyone out there tell me how I can accomplish this same feat in .NET Core?
那么有人可以告诉我如何在.NET Core中实现这一壮举吗? I am currently using this framework setup in my project.json file:
我目前在project.json文件中使用此框架设置:
"frameworks": {
"netcoreapp1.0": {
"imports": [
"dotnet5.6",
"portable-net45+win8"
]
}
},
You can use TimeZoneInfo.ConvertTime
and then choose destinationTimeZone
(the third parameter) to be UTC: 您可以使用
TimeZoneInfo.ConvertTime
,然后选择destinationTimeZone
(第三个参数)为UTC:
var timeZoneInfo = TimeZoneInfo.FindSystemTimeZoneById(viewModel.EventTimeZone);
var completeStartDate =
TimeZoneInfo.ConvertTime(viewModel.StartDate,timeZoneInfo, TimeZoneInfo.Utc);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.