C # Two operations to implement a DateTime time-size comparison
1. Direct comparison
String strTime1 = DateTime.Now.ToString (); String strTime2 = DateTime.Now.AddDays (-1). ToString (); DateTime dt1 = Convert.todatetime (strTime1); DateTime DT2 = Convert.todatetime (strTime2); if (Dt1 > DT2) {//Other actions}
2. Use the CompareTo method to achieve a comparison of two time sizes
String strTime1 = DateTime.Now.ToString (); String strTime2 = DateTime.Now.AddDays (-1). ToString (); DateTime dt1 = Convert.todatetime (strTime1); DateTime DT2 = Convert.todatetime (strTime2); int n = dt1.compareto (DT2); if (n = = true) {//Other action}
C # DateTimePicker Time format is set to 00:00:00 seconds or 23:59:59
String stime = Convert.todatetime (this.dtpStart.Value). ToString ("yyyyMMdd000000"); String etime = Convert.todatetime (this.dtpEnd.Value). ToString ("yyyyMMdd235959");
PS : Gets the stime time format as yyyyMMdd000000, such as 20150525000000
Get etime time format for yyyyMMdd235959, e.g. 20150525235959
This article from "Flower Blossom Fall" blog, declined reprint!
[C #] Comparison of datetime time sizes