c# - timespan to datetime conversion format issue to display datetime chart -


i developing windows forms application , has display datetime line chart real time data every 1 second.

i have display time on x-axis in format of (days:hours:min:sec). time should 00:00:00:00, 00:00:00:01, 00:00:00:02 etc.

i taking first response time(system time) reference time date1. again after 1 sec, sending request, getting response, capturing system time date2 , continuously doing this. getting response timespan subtracting date2 , date1.

but datetime chart x-axis accepts datetime type variable , has convert double using tooadate().

problem: while converting timespan 00:00:06.2867597 datetime variable converting 7/25/2016 12:00:06 am . need fomat 00:00:06 instead of 12:00:06 am.

then using tooadate(), correct double value. please solve problem.

here code:

 datetime date1 = datetime.now; //  {7/25/2016 8:13:29 pm}     datetime date2 = datetime.now; //  {7/25/2016 8:13:30 pm}   timespan time = date2 .subtract(date1);  //  {00:00:01.3922821}      datetime  logtime = convert.todatetime(time.tostring()); // {7/25/2016 12:00:01 am}  

but need logtime value should "00:00:01".

when using datetime automatically show system datetime format. have take string desire output way

string  logtime = convert.todatetime(time.tostring()).tostring("mm/dd/yyyy hh:mm:ss"); 

if want time part then

 string  logtime = convert.todatetime(time.tostring()).tostring("hh:mm:ss"); 

Comments

Popular posts from this blog

jOOQ update returning clause with Oracle -

java - Warning equals/hashCode on @Data annotation lombok with inheritance -

java - BasicPathUsageException: Cannot join to attribute of basic type -