I have a .net core web api where return a data as below when call from xamarin forms
{"id":1,"customer":"XXX Pty Ltd","salesman":"Fred","shipmentDate":"2020-01-08T00:00:00"}
I use Jsonconverter.DeserializeObject method to covert to .Net object, the code as below
var result = JsonConvert.DeserializeObject<Logis[]>(returnJson);
The date is in wrong format. It become 01/08/2020:00:00:00. How I can convert it to 08/01/2020 00:00:00?
My .Net object as below
[JsonProperty("Id")]
public int Id { get; set; }
[JsonProperty("Customer")]
public string Customer { get; set; }
[JsonProperty("Salesman")]
public string Salesman { get; set; }
[JsonProperty("ShipmentDate")]
public DateTime ShipmentDate { get; set; }
[Edit]
In my WebAPI, I modify my ViewModel class by add a string property for the date and format it to the format I needed. I not sure the way I do is correct or not but I get the result I needed.
public class ViewModel
{
public int Id { get; set; }
............
public DateTime ShipmentDate { get; set; }
public string ShipmentDateString
{
get
{
return ShipmentDate.ToString("dd-MM-yyyy");
}
}
}
In xamarin forms, I bind it using ShipmentDateString property instead of ShipmentDate