Solved

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

Posted on 2012-03-19
3
369 Views
Last Modified: 2012-03-20
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");
0
Comment
Question by:searchsanjaysharma
3 Comments
 
LVL 77

Expert Comment

by:arnold
ID: 37739205
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.
0
 
LVL 20

Accepted Solution

by:
BuggyCoder earned 500 total points
ID: 37739243
here is a nice msdn article on timezone conversions, please go through:-
http://msdn.microsoft.com/en-us/library/bb397769.aspx

here is another one, which you might find helpful:-
http://www.xiirus.net/articles/article-_net-convert-datetime-from-one-timezone-to-another-7e44y.aspx
0
 

Author Closing Comment

by:searchsanjaysharma
ID: 37745827
ok
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

790 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question