In Excel. The date or time format is: 42093.6506944444 or 0.650694444444444
Greater than 0 indicates a date (2015-03-30), less than 0 is the time (15:37)
When the C # import reads this column, the conversion error occurs;
Now convert this format to the normal date format:
1 /// <summary>2 ///Digital Conversion Time format3 /// </summary>4 /// <param name= "Timestr" >numbers, such as: 42095.7069444444/0.650694444444444</param>5 /// <returns>Date/Time format</returns>6 Private stringTodatetimevalue (stringstrnumber)7 {8 if(!string. Isnullorwhitespace (strnumber))9 {Ten Decimal Tempvalue; One //first check is not the number; A if(Decimal.tryparse (Strnumber, outtempvalue)) - { - //days, rounding the intDay =Convert.ToInt32 (Math.truncate (Tempvalue)); - //and I don't know why. Minus 1 if it's less than 32, or minus 2. - //Date starting from 1900-01-01 cumulative - //Day = Day < day-1: day-2; +DateTime dt =NewDateTime (1900,1,1). AddDays (Day < +? (Day-1): (Day-2)); - + //hours: Minus the number of days, this number converted hours: (*) ADecimal hourtemp = (tempvalue-day) * -;//gets the number of hours at //Rounding . Number of hours - inthour =Convert.ToInt32 (Math.truncate (hourtemp)); - //minutes: Lose Hours, (*) - //rounding here, otherwise the value will have a 1 minute error. -Decimal minutetemp = Math.Round ((hourtemp-hour) * -,2);//gets the number of minutes - intminute =Convert.ToInt32 (Math.truncate (minutetemp)); in //seconds: Lose minutes, (*) - //rounding here, otherwise the value will have a 1 second error. toDecimal secondtemp = Math.Round ((minutetemp-minute) * -,2);//gets the number of seconds + intSecond =Convert.ToInt32 (Math.truncate (secondtemp)); - the //time format: 00:00:00 * stringResulttimes =string. Format ("{0}:{1}:{2}", $(Hour <Ten? ("0"+hour): hour. ToString ()),Panax Notoginseng(Minute <Ten? ("0"+minute): minute. ToString ()), -(Second <Ten? ("0"+second): second. ToString ())); the + if(Day >0) A return string. Format ("{0} {1}"Dt. ToString ("YYYY-MM-DD"), resulttimes); the Else + returnResulttimes; - } $ } $ return string. Empty; -}
C#,asp.net import Excel, time format a series of numeric conversions.