In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
Most people don't understand the knowledge points of this article "How Java queries data between time periods", so Xiaobian summarizes the following contents for everyone. The contents are detailed, the steps are clear, and they have certain reference value. I hope everyone can gain something after reading this article. Let's take a look at this article "How Java queries data between time periods".
Java Query Time Period Data Question 1
Determine the data between time intervals, just like querying numbers, by between-and method?
Answer 1:
between-and is used to query numeric intervals, not to query the contents of two time intervals. If you want to query, you can try converting the time format to Long.
Question 2
After testing with the postman tool, Java reported an exception: (String type and Date type comparison exception)?
Exception information:
### Error querying database. Cause: java.lang.IllegalArgumentException: invalid comparison: java.util.Date and java.lang.String
### Cause: java.lang.IllegalArgumentException: invalid comparison: java.util.Date and java.lang.String
mybatis--xml
AND create_time =]]> #{startTime}
Answer 2:
Exception reason for comparison between String type and Date type here: in if tag, Date type does not exist String type, just judge directly
AND create_time =]]> #{startTime}
At this point the above problem is solved.
Additional:
Complete time interval comparison code
AND create_time =]]> #{startTime} AND create_time #{endTime}
entity class
//Creation time private Date createTime; //start time private Date startTime; //End time private Date endTime; formatted time difference between startTime and endTime
Format the time difference between startTime and endTime. When the interval exceeds one year, display the date.
If more than one day, the month and day are displayed;
When more than one hour, show how many hours ago;
When more than one minute, how many minutes ago is displayed;
Less than a minute, it shows just now
/** * Format the time difference between startTime and endTime, used for friends circle and other places to display the release time. For example,"45 minutes ago", etc. * @param endTime: release time * @return formatted time display character */public static String getFriendlyTime(Date startTime, Date endTime) { long betweenTime = (endTime.getTime() - startTime.getTime()) / 1000; if (betweenTime
< 0) { return DateTimeUtils.convertDate2String(startTime, "yyyy年MM月dd日"); } if (betweenTime / (60 * 60 * 24 * 365) >0) { //greater than 1 year return DateTimeUtils.convertDate2String(startTime, "yy MM DD"); } if (betweenTime / (60 * 60 * 24 ) > 0) { //More than one day return DateTimeUtils.convertDate2String(startTime, "MM Month DD"); } if (betweenTime / (60 * 60) > 0) { //greater than 1 hour return betweenTime / (60 * 60) + "hours ago"; } if (betweenTime / (60) > 0) { //greater than one minute return betweenTime / (60) + "minutes ago"; } //Less than one minute return "just";} The above is about the content of this article on "Java how to query the data between time periods". I believe everyone has a certain understanding. I hope the content shared by Xiaobian will help everyone. If you want to know more relevant knowledge, please pay attention to the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.