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
347 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 76

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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

747 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now