修改
This commit is contained in:
@@ -61,6 +61,7 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="BaseModel.cs" />
|
||||
<Compile Include="TimestampConverter.cs" />
|
||||
<Compile Include="Request\Arrival.cs" />
|
||||
<Compile Include="Request\Bin.cs" />
|
||||
<Compile Include="Request\Customer.cs" />
|
||||
|
||||
36
NX.ERP.Model/TimestampConverter.cs
Normal file
36
NX.ERP.Model/TimestampConverter.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace NX.ERP.Model
|
||||
{
|
||||
public class TimestampConverter : JsonConverter
|
||||
{
|
||||
public override bool CanConvert(Type objectType)
|
||||
{
|
||||
return objectType == typeof(DateTime);
|
||||
}
|
||||
|
||||
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
|
||||
{
|
||||
return ConvertIntDateTime(int.Parse(reader.Value.ToString()));
|
||||
}
|
||||
|
||||
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
|
||||
{
|
||||
writer.WriteValue(ConvertDateTimeInt((DateTime)value));
|
||||
}
|
||||
|
||||
public static DateTime ConvertIntDateTime(int aSeconds)
|
||||
{
|
||||
return new DateTime(1970, 1, 1).AddSeconds(aSeconds);
|
||||
}
|
||||
|
||||
public static int ConvertDateTimeInt(DateTime aDT)
|
||||
{
|
||||
return (int)(aDT - new DateTime(1970, 1, 1)).TotalSeconds;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user