Link to home
Start Free TrialLog in
Avatar of Member_2_7967608
Member_2_7967608

asked on

C# DateTime format

Hi all,

Can we represent DateTime in C# in below format. I haven't found this format in .Net

2016-08-31T15:00:00-04:00

Here is -4 is UTC offset.  The time is local EST time

 I want to serialize the DateTime to Json in the above format. How do we convert to this format.

Thanks in advance
Avatar of Fernando Soto
Fernando Soto
Flag of United States of America image

Assuming that the DateTime is from a DateTime object you can use the ToString to get it in that format like this
var dt = DateTime.Now;
Console.WriteLine(dt.ToString("yyyy-MM-ddTHH:mm-ss:ffff"));

Open in new window

SOLUTION
Avatar of Kyaw Wanna
Kyaw Wanna
Flag of Thailand image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Member_2_7967608
Member_2_7967608

ASKER

This is my code. How can I set the formatter here.  The datetime is coming from UI as "req2".


 var request = new RestRequest("api/ACSSchedule/", Method.POST) { RequestFormat = DataFormat.Json };
            request.JsonSerializer = new RestSharp.Newtonsoft.Json.NewtonsoftJsonSerializer();
            request.AddBody(req2);
            var response = Execute(request, _client);
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Formatting works with Newtonsoft Json serailizer