Avatar of searchsanjaysharma
searchsanjaysharma
 asked on

How to convert one time zone to another with 24 hour format without using the AM and PM . Use only the Timespan.

TimeSpan.TryParse(datewise + ":" + "00", out _timeOfDay);
                var asd = _dt.ToString().Split(new string[] { " " }, StringSplitOptions.None);
                var _newdatetime = asd[0] + " " + _timeOfDay;
                DateTime oldTime = Convert.ToDateTime(_newdatetime);
                TimeZoneInfo timeZone1 = TimeZoneInfo.FindSystemTimeZoneById("AUS Eastern Standard Time");
                TimeZoneInfo timeZone2 = TimeZoneInfo.FindSystemTimeZoneById(TimeZoneInfo.Local.Id);
                DateTime newTime = TimeZoneInfo.ConvertTime(oldTime, timeZone1, timeZone2);
                DateTime new_Time = TimeZoneInfo.ConvertTimeFromUtc(oldTime, timeZone2);
                TimeSpan timeOfDay = new TimeSpan();
                TimeSpan.TryParse(newTime.ToString(), out  timeOfDay);

                new DateTime(newTime.Ticks).ToString("H tt");
                new DateTime(new_Time.Ticks).ToString("H tt");
C#

Avatar of undefined
Last Comment
searchsanjaysharma

8/22/2022 - Mon
arnold

You should first convert the date, time to unix time in seconds adjusting for time son to GMT, Utc time. You can then convert back in a much simpler, straight forward way way.
http://forums.devshed.com/net-development-87/unix-time-in-c-123865.html
Storing date time in at least GMT, Utc time zone makes transition simpler requiring adjustments by the time zone only. Storing using unix time stamp make the conversion a mathematical function of adding or subtracting the tz value.
ASKER CERTIFIED SOLUTION
BuggyCoder

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
searchsanjaysharma

ASKER
ok
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23