What happened to ConvertTimeToUtc in .NET Core? 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:
var timeZoneInfo=TimeZoneInfo.FindSystemTimeZoneById(viewModel.EventTimeZone);
var completeStartDate=TimeZoneInfo.ConvertTimeToUtc(viewModel.StartDate,timeZoneInfo);
This has worked great, until .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. So can anyone out there tell me how I can accomplish this same feat in .NET Core? I am currently using this framework setup in my project.json file:
"frameworks": {
"netcoreapp1.0": {
"imports": [
"dotnet5.6",
"portable-net45+win8"
]
}
},
You can use TimeZoneInfo.ConvertTime
and then choose destinationTimeZone
(the third parameter) to be UTC:
var timeZoneInfo = TimeZoneInfo.FindSystemTimeZoneById(viewModel.EventTimeZone);
var completeStartDate =
TimeZoneInfo.ConvertTime(viewModel.StartDate,timeZoneInfo, TimeZoneInfo.Utc);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With