0

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.

5
  • What problems are you "facing with milliseconds"? Is it a processing or a display problem? Commented Apr 2, 2022 at 8:12
  • 4
    "8/8/2021 1:38:34 PM +00:00" is just some default output for a DateTime instance. And the dictionaries do not play any role in your problem. The real question you should be asking is: "How do I format a DateTime instance in ISO format?" And you should add the specific ISO variant you are interested in. But then again: this question has been answered many times. Just search for it. Commented Apr 2, 2022 at 8:13
  • @PeterSmith When I am converting to DateTime format milliseconds looks 0. But before conversion milliseconds is exist in the object Commented Apr 2, 2022 at 8:36
  • 1
    You can't remove the time from a DateTime. That's like asking how to remove the 0 from 1.0; 1 is 1.0 is 1.00 is.. The only thing you can do is "not print it" Commented Apr 2, 2022 at 9:07
  • 1
    Storage and display are different. If you want to display it in different ways then you need to look at [format options)(learn.microsoft.com/en-us/dotnet/standard/base-types/…) Commented Apr 2, 2022 at 9:12

1 Answer 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;
        }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.