Unix Time Stamp to .NET DateTime converter for Json.NET
Install-Package UnixTimeConverter
namespace UsageExample
{
public class ApiData
{
[JsonConverter(typeof(UnixTimeConverter))]
public DateTime Date { get; set; }
}
public class ConverterTest
{
[Fact]
public void HappyPath()
{
//Arrange
var apiJson = "{ Date : 1321009871 }";
//Act
var result = JsonConvert.DeserializeObject<ApiData>(apiJson);
//Assert
Assert.Equal(new DateTime(2011, 11, 11, 11, 11, 11, DateTimeKind.Utc), result.Date);
}
}
}
Install .NET Core SDK
Open src
folder in the command prompt.
Then
dotnet restore
dotnet build
Open src\JsonNetConverters.Test
folder in the command prompt.
Then
dotnet test
Library was created with supporting for .NET Standart 1.0
Don't be shy to ask a question or offer something :)