The date the database is stored, even if it is represented by a string, you can also use "Mysql" to find the most recent difference x days, the SQL statement on the date of the comparison (click on the link) described in the Timestampdiff function, the date is not more than one day.
If the date in Java is equal to two of the dates represented as a string,
For example, the comparison of the two with "Yyyy-mm-dd HH:mm:ss" and string form the date, is equal
That can first remove the "-", ":", "" "space, etc., intercept the first 8 strings, that is," YYYY-MM-DD "part, then get a 8-bit long shape, two date subtraction can be.
The following procedure determines whether the "2019-09-06 16:04:07" and the current date "2015-5-7" are the same day.
Package Timedifftest;import java.text.simpledateformat;import java.util.date;class util {public static Boolean Stringtimedaydiff (String stringTime1, String stringTime2) {Long dateTime1 = Long.parselong (Stringtime1.replaceall ("-" , ""). ReplaceAll (":", ""). Replace ("", ""). Substring (0, 8)); Long dateTime2 = Long.parselong (Stringtime2.replaceall ("-", ""). ReplaceAll (":", ""). Replace ("", ""). Substring (0, 8)); return (dateTime1 = = dateTime2)? True:false;}} public class Timediff {public static void main (string[] args) {String dbTime = "2019-09-06 16:04:07"; String nowtime = new SimpleDateFormat ("Yyyy-mm-dd HH:mm:ss"). Format (New Date (System.currenttimemillis ())); System.out.println (Util.stringtimedaydiff (Dbtime,nowtime));}}
The results of the operation are as follows:
"Java" is more than 1 days apart from two times in a string representation