Handling ServiceStack DateTime

I am having a problem with the DateTime format used by ServiceStack.

For example, I have a simple request object like this.

public class GetAllUpdatedStudents : IReturn<GetAllUpdatedStudentsResponse>
{
    public DateTime LastUpdate { get; set; }
}

When sending DateTime (mm / dd / yyyy) from 12/10/2016, ServiceStack will convert it to the DateTime format (dd / mm / yyyy), so the system considers this to be October 12, and not December 10.

How to tell ServiceStack not to do this, and we need the mm / dd / yyyy format when binding DateTime properties to object requests?

+4
source share
1 answer

DateTime - ISO 8601. ServiceStack IS0 8601, ServiceStack , mm/dd/yyyy, dd/mm/yyyy. - , YYYY-MM-DD.

mm/dd/yyyy, , :

public class GetAllUpdatedStudents : IReturn<GetAllUpdatedStudentsResponse>
{
    public string LastUpdate { get; set; }
}

, DateTime .

DateTime, - :

JsConfig.DeSerializeFn = str => {
    return DateTime.ParseExact(str,"MM/dd/yyyy",null);
};

, .

+1

Source: https://habr.com/ru/post/1664310/


All Articles