DateTimeOffset Support in Compact Framework 3.5
Does anyone know开发者_StackOverflow if the data type "DateTimeOffset" is supported in the .NET Compact Framework 3.5?
No, it's not. Can you tell us what your usage scenario is and maybe we can suggest a workaround? My guess is you can create your own class something like this that would probably work:
class MyDateTimeOffset
{
public DateTime UTCTime { get; set; }
public int BiasInMinutes { get; set; }
public DateTime AsLocalTime()
{
var localBias = (DateTime.Now - DateTime.UtcNow).TotalMinutes;
return UTCTime.AddMinutes(BiasInMinutes - localBias);
}
}
I recommend you to store your DateTime in a Int64 and use the functions ToFileTimeUtc() and DateTime.FromFileTimeUtc(long).ToLocalTime() that exists on both framework versions (.net CF and .net).
DateTime localDate = DateTime.Now; // our current local DateTime
long date = localDate.ToFileTimeUtc(); // stores it as an Int64
DateTime dateUTC = DateTime.FromFileTimeUtc( date ); // gets UTC DateTime from the Int64
DateTime backTolocal = dateUTC.ToLocalTime(); // converts the UTC DateTime to LocalTime
精彩评论