C# Datetime to double and Double to datetime 변환. (ChartDirector chartTime…
페이지 정보
본문
프로젝트를 진행하고 있는 S사 시스템중에 ChartDirector를 사용하는 곳이 있네요. 아무튼, X Axes의 데이타가 일(Day) 단위와 시프트(Shift, 8, 16, 24) 단위로 변환되는 항목이 있습니다. 이 때 ChartDirector는 차트 고유 함수로 변환해주는게 있는데요. TeeChart는 이런게 없다보니 직접 변환하도록 해야 했습니다. ChartDirector의 변환 함수는 아래 링크에서 확인할 수 있어요. 신텍스를 참고해서 동일하게 변환했습니다.
Chart.chartTime (advsofteng.com)
이 함수를 C# 메소드로 만들면 아래와 같이 변환할 수 있습니다.
public static double DateTimeToSeconds(DateTime date)
{
// C# Style
// return date.ToOADate();
DateTime origin = new DateTime(1, 1, 1, 0, 0, 0, DateTimeKind.Local);
TimeSpan diff = date - origin;
double temp = Math.Floor(diff.TotalSeconds;
return temp;
}
반대로 Seconds를 DateTime로 변환할수도 있습니다.
public static DateTime SecondToDateTime(double seconds)
{
// C# Style
// return DateTime.FromOADate(seconds);
DateTime origin = new DateTime(1, 1, 1, 0, 0, 0, DateTimeKind.Local);
DateTime temp = origin.AddSeconds(seconds);
return temp;
}
개발자에게 후원하기
추천, 구독, 홍보 꼭~ 부탁드립니다.
여러분의 후원이 빠른 귀농을 가능하게 해줍니다~ 답답한 도시를 벗어나 귀농하고 싶은 개발자~
감사합니다~
추천0 비추천0
- 이전글전체 이미지 파일 이름에서 이미지 확장자 추출하는 방법. (How to extract image extensions.) 21.05.06
- 다음글엔터프라이즈급 프로젝트를 운영하기 위한 기술 스택. (Tech Stack for running enterprise level projects.) 21.05.05
댓글목록
등록된 댓글이 없습니다.