I have the following:
Dim myTZ As AFTimeZone = myAFSrv.ServerTimeZone Dim wrongTZ As DateTime = New DateTime(2015, DateTime.Now.Month, DateTime.Now.Day, DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second, DateTimeKind.Utc) Dim rightTZ As DateTime = AFTimeZone.ToLocalTime(myTZ, wrongTZ)
If I write everything to console, I get the following:
(UTC+08:00) Kuala Lumpur, Singapore
4/30/2015 10:20:33 AM
4/30/2015 6:20:33 PM
So it seems that it works.
The main difference I see is in our arguments in the ToLocalTime method.
- Your destination AFTimeZone isn't anything you seem to have defined in the code you've shown, could that be the issue?
- You are using the LocalTime property of your DateTime Structure. As far as I am aware, DateTime Structures do not have a LocalTime property.
Thank you for your quick response. My problem is that I am trying to convert a AFtime to the correct time zone. Maybe I didn't explain detailed enough from my previous sample code. Here is what I am trying to do. I have a AFTime defined as a UTC time in my application. After the appropriate calculation I want to convert it back to my local time so I can print it to the local user.
Dim wrongTZ As DateTime = New DateTime(2015, DateTime.Now.Month, DateTime.Now.Day, DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second, DateTimeKind.Utc)
Dim wrongTZAFTime As AFTime = New AFTime(wrongTZ )
Dim tz As AFTimeZone = g_AFSystem.ServerTimeZone ' this AFTimeZone tz is correctly showing in my debug watch window as below
The problem is with the following line that I have to convert AFTime wrongTZAFTime to DataTime by calling wrongTZAFTime.UtcTime then the returned rightTZ is not right. no conversion at all.
Dim rightTZ As DateTime = AFTimeZone.ToLocalTime(tz, wrongTZAFTime.UtcTime )
Can you give a try on your side please?
Thanks you very much for your time.
Add this line at the top
If it still doesn't work, try troubleshooting by using
to see what it returns.
Great, it works. Thanks. But why do we have to call on connect()? If the connection is not there why we can get the coorect AFTimeZone already ?
I am glad it works! In my case, if I didn't connect, the timezone info will be wrong though