import java.util.Date;
import java.text.SimpleDateFormat;
import com.github.novmorgan.springframework.util.MomentUtils;
public class DateParserExample {
public static void main(String[] args) {
String dateString = "2022-01-01";
Date date = MomentUtils.parse(dateString).toDate();
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd");
String formattedDate = dateFormat.format(date);
System.out.println("Formatted date: " + formattedDate);
}
}
import java.util.Date;
import com.github.novmorgan.springframework.util.MomentUtils;
public class DateCalculationExample {
public static void main(String[] args) {
Date currentDate = new Date();
Date nextWeek = MomentUtils.of(currentDate).addWeeks(1).toDate();
Date previousMonth = MomentUtils.of(currentDate).subtractMonths(1).toDate();
System.out.println("Next week: " + nextWeek);
System.out.println("Previous month: " + previousMonth);
}
}
import java.util.Date;
import com.github.novmorgan.springframework.util.MomentUtils;
public class DateComparisonExample {
public static void main(String[] args) {
Date currentDate = new Date();
Date compareDate = MomentUtils.parse("2022-01-01").toDate();
boolean isAfter = MomentUtils.of(currentDate).isAfter(compareDate);
boolean isBefore = MomentUtils.of(currentDate).isBefore(compareDate);
boolean isEqual = MomentUtils.of(currentDate).isEqual(compareDate);
System.out.println("Is current date after compare date? " + isAfter);
System.out.println("Is current date before compare date? " + isBefore);
System.out.println("Is current date equal to compare date? " + isEqual);
}
}
<dependencies>
<!-- Other dependencies -->
<dependency>
<groupId>com.github.novmorgan</groupId>
<artifactId>momentjavaspringframework</artifactId>
<version>2.21</version>
</dependency>
</dependencies>