I have the following issue. I am located in Germany, so right now my time is UTC+2.
The following happens: when I send for example a date with time 17:00 to the server using the swagger generated service proxy, it's saved in the database as 15:00 which is correct so far. As far as I can tell, it is converted using MomentJS in the service proxy.
However, when receiving the date, I cannot get it back to the local time. I tried calling moment.utc(receivedDate).local().toString() but this does nothing because if you check the isUTC boolean of the receivedDate it is already false, so it is considered converted already. But it's not. I just can't get it back to the local time. Should I use something else than moment to convert it back?
5 Answer(s)
-
0
Hi,
Are you using momentFormatPipe ? This might be related to https://github.com/aspnetzero/aspnet-zero-core/issues/2423
-
0
Hi,
no I'm not. I tried this approach but it's not working either. I cannot find any information about for example the ClockProvider class and how to handle time zones. Any documentation availabe for this I don't know of? The only thing I know for sure is that the service proxies generated by nswag convert time to UTC before sending it to the server. But after receiving the time from the server I just can't get it back to local time. Is this something that should already happen on the server side or is it handled completely by moment in the angular application?
-
0
Hi,
The related documentation on ABP Framework is here https://aspnetboilerplate.com/Pages/Documents/Timing.
Could you try converting MomentJs to Date and regenerate your service-proxies again ?
-
0
Hey, thanks again for your help.
I did something different yesterday and it worked. First thing I noticed was, that there is no General tab in the host settings where I could change the timezone. It appeared after adding the line
Clock.Provider = ClockProviders.Utc;
to the Startup class. After setting the timezone it magically worked. Still don't know what's going on behind the scene though. I guess the moment framework uses the timezone setting and returns the appropriate time instead of UTC? -
0
Hi,
Yes, when setting
Clock.Provider = ClockProviders.Utc;
timezone selection becomes available. In that case, dates are sent to client app as UTC dates as well but client app also retrieves the timezone setting for the logged in user and momentFormatPipe converts UTC date to users timezone when displaying it.