'How to remove +00.00 from dictionary value c#

I have a Dictionary<string, object> collection.

and the dictionary object looks {8/8/2021 1:38:34 PM +00:00} (datetime object)

Facing some milliseconds problem because of +00:00.

Need to remove +00:00 from the dictionary object. Is there any way to remove that character from dictionary?

My ultimate goal is convert my datetime object into ISO format. Facing issue while converting because of +00.00

Please help me to resolve this issue.



Solution 1:[1]

You can use LocalDateTime property of DateTimeOffset object to convert to DateTime. Assuming there is only DateTimeOffset in your dictionary you can do this

        Dictionary<string, object> dictionary = new Dictionary<string, object>();

        dictionary.Add("1", new DateTimeOffset(DateTime.Now));
        dictionary.Add("2", new DateTimeOffset(DateTime.Now+TimeSpan.FromDays(1)));

        foreach (string key in dictionary.Keys)
        {
            dictionary[key] = ((DateTimeOffset)dictionary[key]).LocalDateTime;
        }

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Thomas Barbare