두 날짜간의 미래와 과거 혹은 같은날 여부를 확인하기 위한 코드
using System; using System.Drawing; using System.Windows.Forms; namespace Exams { public partial class EtcTest : Form { public EtcTest() { InitializeComponent(); } private void simpleButton1_Click(object sender, EventArgs e) { DateTime dt1 = new DateTime(2009, 1, 1); DateTime dt2 = new DateTime(2012, 12, 1); DateTime dt3 = new DateTime(2009, 1, 1); int compare1 = dt1.CompareTo(dt2); //-1 : dt2보다 작음(과거) int compare2 = dt2.CompareTo(dt1); // 1 : dt1보다 큼(미래) int compare3 = dt3.CompareTo(dt1); // 0 : dt1과 같음(같은날) } } }
'프로그램 경험 > .Net' 카테고리의 다른 글
[C#] PC의 IP 변경하기 (0) | 2009.10.29 |
---|---|
[C#] PC의 IP주소 얻기 (0) | 2009.09.17 |
[C#] PDA 에뮬레이터에서 인터넷 하기 (0) | 2009.09.10 |
[C#] 프로그램 시작하자 마자 종료할때 오류 (0) | 2009.09.10 |
[C#] 윈폼에서 웹페이지로 데이터 전달 (0) | 2009.09.10 |