I want to get midnight time of specific timezone in UTC. For e.g. consider my local machine timezone is +05:30. Please see below screenshot. I used https://www.epochconverter.com/ site for conversion.
In above example I enter midnight time in +05:30 and it give UTCtime for it.
Note: I am resetting my machine timezone to (UTC)Coordinated Universal Time.
So here what I want to find is, that UTC datetime. For this I have stored user timezone information. I get timezone info using below code.
TimeZoneInfo userTz = TimeZoneInfo.FindSystemTimeZoneById(LoginSessionDO.TimeZoneId);
So, I want to find midnight time of any timezone in UTC. How can I do that in c#?
for e.g. +05:30 - 2018-07-07 00:00:00 UTC- 2018-07-06 18:30:00
Sorry for uncleared question. I will explain my scenario.
EDIT:-
I have stored some user's activity data in Sql server
table which contains dateofactivity
column. All records datetime stored in UTC. So in frontend side, I want to fetch all todays activity records of user from midnight(When days start). If user is in +05:30
timezone & he want to fetch all 7th July 2018 00:00:00 records then I need to pass 6th July 2018 18:30:00.Now suppose another user is in Europe/Amsterdam (CEST) GMT +02:00 so want to find midnight time of Europe/Amsterdam in UTC.
Take the midnight time in your local timezone, get the timezone info for your timezone and call ConvertTimeToUtc
var tz = TimeZoneInfo.FindSystemTimeZoneById("Sri Lanka Standard Time");
var midnight = new DateTime(2000, 1, 1, 0, 0, 0, DateTimeKind.Unspecified);
var converted = TimeZoneInfo.ConvertTimeToUtc(midnight, tz);
Console.WriteLine(midnight); //2000-01-01 00:00:00
Console.WriteLine(converted);//1999-12-31 18:30:00
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