Conversion of Coldfusion Date format to C Sharp format
I am trying to convert a coldfusion code to csharp but with little success. Cold fusion code goes as below:
<CFSET iTimeBefore = #TimeFormat( Now(), 'hh:mm:ss tt' )#>
Some DB Operation here...
<CFSET iTimeBefore = #Caller.iTimeBefore#>
<CFSET iTimeAfter = #TimeFormat( Now(), 'hh:mm:ss tt' )#>
<cfset TimeDiff = #iTimeAfter# - #iTimeBefore#>
<CFSET TimeDiff = TimeDiff*100000>
<CFSET TimeDiff = #NumberFormat(TimeDiff, '99.999')#>
Essentially, the code is checkiing for time elapsed while performing DB operation. I have tried to use 'TimeSpan' class in C# 开发者_Go百科but it gives current time as follows:
TimeSpan dtOprnStartTime1 = DateTime.Now.TimeOfDay;
Output:
20:15:12.9661624
Kindly advise.
Try this:
DateTime before = DateTime.Now;
// Some DB Operation here
TimeSpan elapsed = DateTime.Now - before;
Console.Write(elapsed);
精彩评论