Click here to Skip to main content
15,845,785 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have tried to display datetime in string with below code but getting +5:30 end of the string.
logtime = "2018-04-05T19:30:24+08:00";

out put is displaying with

could you please help me how to display same thing we are getting from API in string?

What I have tried:

string logtime = "2018-04-05T19:30:24+08:00";
            DateTime dta = Convert.ToDateTime(logtime);
            logtime = dta.ToString("yyyy-MM-ddTHH:mm:ss");

Updated 5-Apr-18 3:49am
Maciej Los 5-Apr-18 8:02am    
What are you trying to achieve?

Well, 2018-04-05T19:30:24+08:00 is proper date, which contains information about DateTimeOffset[^] for specific time zone[^].

string sdate = "2018-04-05T19:30:24+08:00";
DateTimeOffset dto = DateTimeOffset.Parse(sdate);
Console.WriteLine("'{0}' => local time: '{1}'", sdate, dto.LocalDateTime);
Console.WriteLine("'{0}' => universal time: '{1}'", sdate, dto.UtcDateTime);

'2018-04-05T19:30:24+08:00' => local time: '2018-04-05 13:30:24' //for Poland ;)
'2018-04-05T19:30:24+08:00' => universal time: '2018-04-05 11:30:24'
Share this answer
You are parsing a string that contains a TimeZone offset, so the DateTime will replicate that. Use one of the methods provided by DateTime Structure (System)[^].
Share this answer
This is spelled out in the documentation for DateTime.ToString()[^].
Share this answer
DGKumar 6-Apr-18 7:00am    
HI I want display same format what i got from API.
DateTime dateTime = new DateTime();
dateTime = Convert.ToDateTime("2018-04-05T19:30:24+08:00");

from api i am getting "2018-04-05T19:30:24+08:00"
need to display samething in UI "2018-04-05T19:30:24+08:00"
Dave Kreskowiak 6-Apr-18 8:24am    
You didn't read that link. You're just looking for someone to write your code for you.

TEACH YOURSELF. If you don't have this skill, you're not going to survive in this business. Custom Date and Time Format Strings | Microsoft Docs[^]

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900