1

I have created a model class and i am instantiating that class to insert data in that and then passing that class object to searlize to json.Here i am just using hardcoded date to get the json. But I am getting date like

"DateOfBirth":"1959-12-11T06:30:00+05:30"

here is my code

// Arrange
Driver driver = new Driver();
driver.Gender = Gender.Male;
driver.DateOfBirth = DateTime.Parse(string.Format("{0}-01", "11-Dec-1959"));            

// Act
string output = JsonConvert.SerializeObject(driver);

// Assert
Console.WriteLine(output);

also below is my class

public class Driver
{
    public Gender Gender { get; set; }
    public DateTime DateOfBirth { get; set; }
}

Can anybody suggest?

Soner Gönül
  • 97,193
  • 102
  • 206
  • 364
shreyas35
  • 145
  • 9
  • 1
    What target framework of your project? Starting from .NET 6 you can use ```DateOnly``` https://learn.microsoft.com/en-us/dotnet/api/system.dateonly?view=net-6.0 – Andrii Khomiak Jun 14 '22 at 10:53
  • also here is custom DateTime serialization https://stackoverflow.com/a/18639829/7357322 – Andrii Khomiak Jun 14 '22 at 10:55

0 Answers0