Closed DanyLinuxoid closed 4 months ago
Fixed thanks to ChatGPT, code:
using System;
using System.Threading.Tasks;
using NetJSON;
public class Program
{
public static async Task Main(string[] args)
{
// Настройки NetJSON для использования формата ISO с указанием UTC
var settings = new NetJSONSettings
{
DateFormat = NetJSONDateFormat.ISO,
};
var testme = new TestMe
{
DateTime = DateTime.Now.ToUniversalTime(),
};
// Сериализация
var json = NetJSON.NetJSON.Serialize(testme, settings);
Console.WriteLine(json); // Проверка сериализованного вывода
// Десериализация
var recreatedObject = NetJSON.NetJSON.Deserialize<TestMe>(json, settings);
Console.WriteLine(recreatedObject.DateTime); // Проверка десериализованного вывода
}
}
public class TestMe
{
public DateTime DateTime { get; set; }
}
Very nice to figure the documentation with gpt
If you save to file DateTime in UTC format by using '.ToUniversal()', and try to retrieve it the same way, library retrieves it in local formar without 'Kind' specified.
Just change path to file and run code:
This will save DateTime as UTC. but after retrieval Date will be in local format and 'Kind' property will be 'Unspecified'