-2
최종 날짜 값은 20080405
과 같아야하지만 20080229
으로 표시됩니다.날짜 평균을 갖는 방법
public class Program
{
public static void Main(string[] args)
{
DateTime dt1 = new DateTime(dt);
List<DateTime> arryDates = new List<DateTime>();
Decimal[] avgdatetimevalues = { 20080229, 20080304, 20080304, 20080224 };//(Sum =61; sum/4 = 20080265)
// the final date value should be something like 20080405 but this is showing as 20080229
try
{
for(int i = 0; i< avgdatetimevalues.Length; i++)
{
arryDates.Add(ValueToDate(avgdatetimevalues[i]));
}
var cnt = arryDates.Count();
double temp = 0D;
if (cnt > 0)
{
for (int i = 0; i < cnt; i++)
{
temp += (arryDates[i].Ticks/(double)cnt);
}
var average = new DateTime((long)temp);
}
}
catch (Exception ex)
{
throw;
}
}
public static DateTime ValueToDate(decimal dt)
{
DateTime dates;
DateTime.TryParseExact(dt.ToString(), "yyyyMMdd", CultureInfo.InvariantCulture, DateTimeStyles.None, out dates);
return dates;
}
}
시도한 코드를 게시 할 수 있습니까? – Isaac
구현 코드를 추가하고 최종 날짜 값을 찾고 – Joyfulkris
일부 날짜의 "평균"(모든 의미)이 모든 날짜 이후 * 일 수있는 방법은 무엇입니까? 2008-02-29 플러스 몇 시간 실제로 올바른 소리. 또한 왜 실제 DateTime 객체 대신 십진수를 사용하고 있습니까? –