I have a Timespan variable, which has time in local time zone but for a database ( cold type time) I need to pass UTC . How do I do this? Also I need to get UTC to Local time to populate Timespan variable on pageLoad. Thanks!!!
+1
A:
I suppose I would load the TimeSpan into a DateTime, then get the universal time from the DateTime and convert it back again.
var dt = new DateTime( timeSpan.Ticks );
var utc = dt.ToUniversalTime();
chaiguy
2010-07-28 14:38:41
Following won't convert 8PM eastern correctly to UTC Dim dt As New DateTime(time.Ticks) dt = dt.ToUniversalTime() Dim dtUniversal As New TimeSpan(dt.Ticks)
2010-07-28 15:40:18
Are the ticks representing different things perhaps? Different systems use different tick representations--usually the date to start counting milliseconds from. If you can convert your timespan into specific values for year, month, day, etc. you can build a DateTime from those values and then convert it to UTC.
chaiguy
2010-07-29 01:58:47
As you suggested, How do I build datetime? All I am storing in the database is hour and default minutes and seconds are alwyas 00. eg. My value stored is 01:00:00 how do I convert this to dateTime? - thanks
2010-07-29 12:24:18
I will accept this one I made few changes but it was a good starting point for me - thanks
2010-07-29 13:49:28