Hi, I am a bit stuck here.
When sending DateTime values to server, should I do anything special on client side? Like convert the dates to some format or use moment or ?
On the server, I can then use Clock.Normalize(Convert.ToDateTime('Date From Client')) to store the value in UTC in the DB?
On some entities, when I return them to client I notice the CreationTime is "2017-03-09T00:41:42.647Z" for example. I guess, the CreationTime is stored in UTC, so how could I return my values from server in that format?
I am a bit confused in here.
Appreciate your help.
Bilal
8 Answer(s)
-
0
Hi,
Actually when returning data from server to client and vice versa, ABP handles date time normalization. You need to choose which Clock Provider (UTC, Local, Unspecified) to use.
When sending data from client to server, you can format your date with moment, we do it in that way in our projects.
-
0
Thanks Ismail :)
Can you refer me to a sample code where you use moment to prepare date before sending it to server, other than AuditLog?
Regards Bilal
-
0
Hi,
As far as I remember, we used it only in audit logs. Please ask if there is an unclear point for you for the usage in audit logs.
-
0
Sure, I will check it and get back to you. Many thanks
-
0
Hi Ismail,
Seems the Date issue is still not clear to me. I checked the audit logs, the idea is not clear there.
When sending datetime from client to server, what shall i do to the date? Always make sure it is sent as per client timezone? How to do so in Abp?
On submitting a form, on server, Abp based on configured provider to normalizes the date input?
Thanks
-
0
Hi,
I assume you are using UtcClockProvider in your application.
The idea is simple actually. You send a date from client to server, it does not matter if it is UTC or not, ABP normalizes this date with Clock.Normalize. If you are using UtcClockProvider, it converts given date to UTC, if it is already UTC then it does not do anything.
When you are sending a date from server to client, same thing happens. So in your case client side gets an UTC date. In the client side we use momentjs to show dates.
We also use moment timezone library and set it's timezone to user's current timezone and momentjs displays dates in the user's timezone.
So in this case Sending 2017-03-22T05:00:00+04:00 or 2017-03-22T03:00:00+02:00 or 2017-03-22T01:00:00Z will be the same.
-
0
Thanks for the explanation.
Can you show me in the code where this conversion is happening on both, the client side and server side?
Thanks
-
0
Hi,
It is done in ABP, following links are for MVC and WebApi <a class="postlink" href="https://github.com/aspnetboilerplate/aspnetboilerplate/blob/master/src/Abp.AspNetCore/AspNetCore/Mvc/ModelBinding/AbpDateTimeModelBinder.cs">https://github.com/aspnetboilerplate/as ... lBinder.cs</a> <a class="postlink" href="https://github.com/aspnetboilerplate/aspnetboilerplate/blob/master/src/Abp.Web.Api/WebApi/Controllers/Dynamic/Binders/AbpApiDateTimeBinder.cs">https://github.com/aspnetboilerplate/as ... eBinder.cs</a>