1

I have a C# class which is used as a API json response. I have some properties defined as DateTimeOffset.

public DateTimeOffset Time1 { get; set; }
public DateTimeOffset Time2 { get; set; }

The client receives the format as: 2024-01-02T15:26:13+00:00 but the required format is: 2011-01-25T11:53:22.010Z

Initially, I thought of storing as string doing format conversion using ToString() but as some of the properties are used in the program for date calculation, I cannot convert all to string.

I saw online that there are attributes that can be used on DateTime but I cannot find one for DateTimeOffset.

How do I use annotation to convert the format for DateTimeOffset ?

Thanks.

3
  • 1
    Why do you think an annotation is the way to go? Are you open to different approaches? What json lib is in use? System.Text.Json or Newtonsoft?
    – Fildor
    Commented Jan 4, 2024 at 9:18
  • @Fildor Newonsoft. Annotation because I saw it was possible for DateTime. Yes, very open to any working solution. I think I saw one that say to write some converters but I couldn't find it again.
    – EBDS
    Commented Jan 4, 2024 at 14:01
  • I saw a vote to close my question, reason being need more clarify. Is it not clear ? I want to know how I can annotate the DateTimeOffset property, if it's possible. Please don't close my question. Thanks.
    – EBDS
    Commented Jan 4, 2024 at 14:03

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.