I am developing an application which needs to work in multiple locales/timezones. I have run into what should be a simple issue but because of the way ABP works, it is proving not so simple to fix.
Issue: ABP is retrieving DateTimes from the DB already pre-localised. I want to retrieve the DateTimes as ISO YYYY-MM-DD HH:MM:SS so that when moment.js receives the data on the client-side I have a common starting point i.e. ISO. From there I can format easily to the correct locale.
I do not want to have to manually specify the format for each locale with a switch statement but rather create the moment from ISO like follows:
var date = moment('2020-05-22 10:05').utc(); //works for an ISO date
var date = moment('22/05/2020 10:05').utc(); //Invalid date
var date = moment('22/05/2020 10:05', 'DD/MM/YYYY HH:mm').utc(); //Works but I don't want to have to manually specify this for each locale.
But at present I cannot do this because the returned DateTime is always localised. The ABP & DotNetZero forums state that the DateTime should be returned as UTC but this does not seem to be the case.
Application_start() in global.asax also contains the following definition:
Clock.Provider = ClockProviders.Utc;
My controller code (sample naming)
var query = _someRepository.GetAll();
var rows = query.Select(a => new RowViewModel
{
Id = a.Id,
Name = a.Name,
CreatedBy = a.CreatorUser.Name + " " + a.CreatorUser.Surname,
CreatedOn = a.CreationTime //Returns 22/05/2020 10:05:05, I want 2020-05-22 10:05:05
});
How can I get ABP to return as ISO date from my Controller/EF query? Any info would be welcome.
In answer to a comment below, this is what the DateTimeKind data looks like for the returned dates:
