java.util.date

“no suitable method found for between(Date, Date)" when trying to calculate difference in days between two dates

99封情书 提交于 2021-02-05 12:32:15
问题 How to calculate the difference between current day and date of the object that user had previously selected from jXDatePicker swing component and that had been added as Date to that object. In my current code at the last line I'm getting this error message: no suitable method found for between(Date, Date) Date currentDate = new Date(); Date objDate = obj.getSelectedDate(); //getting date the user had //previously selected and that been //added to object long daysDifference = ChronoUnit.DAYS

How to change the value new Date() in java

限于喜欢 提交于 2021-02-05 08:40:19
问题 In my application, the date and time need to be changed frequently when the tester tests the application. Currently, we have to use the system command date-s to change the system time,But this will cause other applications on the server to be affected as well。I want to change the Date() only this application, and I don't want to change the application itself, because there are so many places where new Date is used 回答1: The java.util.Date API is very very old. It was replaced by the Calendar

String (Date and Time) to Unix Timestamp in Java [duplicate]

淺唱寂寞╮ 提交于 2021-01-29 05:30:34
问题 This question already has answers here : Convert a date format in epoch (5 answers) How to convert timestamp string to epoch time? (4 answers) Closed 2 years ago . I am pulling data from an API, and one of the pieces of data I get is a date and time. The date and time is returned in a string format and I need to get that in to a Unix Timestamp for my mySQL database. The String looks like: "2018-10-23 18:00:00" Does anyone know how I would go about getting that from a String to a Unix

grails 4 groovy's date enhancement methods missing

只愿长相守 提交于 2021-01-03 05:25:37
问题 In a previous version of grails I was able to use the groovy enhanced version of java.util.Date found here here. After upgrading to grails 4, all those methods throw no signature of method on java.util.Date. Somehow the groovy additions aren't being picked up. def fdate=new Date(); out << fdate.format("MM/dd/yyyy") //No signature of method: java.util.Date.format() 回答1: Add a dependency to groovy-dateutil to your build.gradle : runtime 'org.codehaus.groovy:groovy-dateutil' The relevant

grails 4 groovy's date enhancement methods missing

假装没事ソ 提交于 2021-01-03 05:22:40
问题 In a previous version of grails I was able to use the groovy enhanced version of java.util.Date found here here. After upgrading to grails 4, all those methods throw no signature of method on java.util.Date. Somehow the groovy additions aren't being picked up. def fdate=new Date(); out << fdate.format("MM/dd/yyyy") //No signature of method: java.util.Date.format() 回答1: Add a dependency to groovy-dateutil to your build.gradle : runtime 'org.codehaus.groovy:groovy-dateutil' The relevant

static final Date field in a java class

ぐ巨炮叔叔 提交于 2020-08-25 05:00:10
问题 We've a public static util method which can parse a string and return a Date object, but it also throws ParseException in case the string parsed cannot be converted to a Date object. Now, in another class I would like to have a static final Date initialized to a value using the util method described above. But given that the util method throws ParseException, this is not allowed. This is what I want to do, which is not allowed public static final MY_DATE = Util.getDateFromString('20000101');

JSTL Date comparison

天涯浪子 提交于 2020-07-18 09:33:38
问题 I've seen some posts about date comparisons in JSTL, but I still can't get it to work. I have a date field, which I want to test whether is after 01-01-1970 . <c:if test="${user.BirthDate > whatGoesHere}"> <doSomeLogic/> </c:if> Maybe a bean should be used? Thanks ! 回答1: Just use <fmt:formatDate> to extract the year from it so that you can do the math on it. <fmt:formatDate value="${user.birthDate}" pattern="yyyy" var="userBirthYear" /> <c:if test="${userBirthYear le 1970}"> <doSomeLogic/> <

Java: check if a given date is within current month

那年仲夏 提交于 2020-03-17 16:24:25
问题 I need to check if a given date falls in the current month, and I wrote the following code, but the IDE reminded me that the getMonth() and getYear() methods are obsolete. I was wondering how to do the same thing in newer Java 7 or Java 8. private boolean inCurrentMonth(Date givenDate) { Date today = new Date(); return givenDate.getMonth() == today.getMonth() && givenDate.getYear() == today.getYear(); } 回答1: Time Zone The other answers ignore the crucial issue of time zone. A new day dawns

Java: check if a given date is within current month

落爺英雄遲暮 提交于 2020-03-17 16:24:07
问题 I need to check if a given date falls in the current month, and I wrote the following code, but the IDE reminded me that the getMonth() and getYear() methods are obsolete. I was wondering how to do the same thing in newer Java 7 or Java 8. private boolean inCurrentMonth(Date givenDate) { Date today = new Date(); return givenDate.getMonth() == today.getMonth() && givenDate.getYear() == today.getYear(); } 回答1: Time Zone The other answers ignore the crucial issue of time zone. A new day dawns