DateTime comparison
I used the date comparison in the log summary. I need to compare the time of the release log and the current date. If it is released within three days, then I will add "new" in front of this log.
My previous algorithm is very troublesome, it is to convert the string into plasticings and then calculate.
I want to use DateTime to directly compare. I first convert the release date (string) into a date type:
/ Calculating Release Date
DateTime Pubdate = New DateTime ();
// pubdate = item ["creator"];
String strpubdate = item ["creator"] .tostring ();
StrPubdate = strpubdate.substring (0, strpubdate.indexof ("));
String stry = strpubdate.substring (0, 4);
String strat = strpubdate.substring (5, strpubdate.length-5);
INT INTINDEX = STRT.INDEXOF ("-");
String strm = strt.substring (0, intIndex);
INTINDEX ;
Strt = strt.substring (intIndex, strt.length-intIndex);
String strd = st.
DateTime DT1 = New DateTime (int.parse (stry), int.Parse (STRM), (INT.PARSE (STRD)), 0, 0, 0);
At the beginning of the beginning, I took it directly in this statement for three days, the statement is this:
DateTime DT1 = New DateTime (int.Parse (stry), int.parse (STRM), (int.Parse (STRD) 3), 0, 0, 0, 0);
As a result, it is always an error. Where is the reason?
I followed the debugging and found the problem. When the published log is on the 28th of the month, since it is directly connected to the conversion, such as 29 3 = 32, 32 is not a way to translate into a date type.
So, I correct this error, then when compared, use DateTime.Adddays (3) to complete this operation:
// Calculate the current date
DateTime Currentdate = new datetime ();
Currentdate = DATETIME.NOW;
CurrentDate { Str = STR "! New"; } If you only want to compare if the date is equal, you can use DateTime.comPare (DT1, DT2).