I am developing a project in Xamarin Studio using C#. Its a .net PCL project and my profile is 78. My problem is, i am unable to convert a DateTime from UTC to specified timezone. I am using below code to convert DateTime from UTC to specified local TimeZone.
DateTime dateTime = (TimeZoneInfo.ConvertTime (DateTime.SpecifyKind (DateTime.UtcNow, DateTimeKind.Utc), profile.TimeZone));
I am getting below exception
The Kind property of the dateTime parameter is DateTimeKind.Utc, but
the sourceTimeZone parameter does not equal TimeZoneInfo.Utc.
In PCL TimeZoneInfo.ConvertTime
doesn't have a parameter for specifying the TimeZoneInfo sourceTimeZone
. It has only 2 overloads with below parameters.
ConvertTime(DateTime, TimeZoneInfo) & ConvertTime(DateTimeOffset,
TimeZoneInfo)
TimeZoneInfo exist only to specify destination TimeZoneInfo.
Also it doesn't have TimeZoneInfo.ConvertTimeFromUtc, TimeZoneInfo.ConvertTimeToUtc
Methods.
Please someone help me to fix this.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…