GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — BAEL-7109 - added code to demostrate how to get max date in java (#14… · FEDENG01/tutorials@149cf39

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • core-java-modules/core-java-8-datetime-2/src
    • main/java/com/baeldung/maxdate
      • DateComparison.java
      • MaxDateDisplay.java
    • test/java/com/baeldung/maxdate
      • DateComparisonUnitTest.java
      • MaxDateDisplayUnitTest.java
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎core-java-modules/core-java-8-datetime-2/src/main/java/com/baeldung/maxdate/DateComparison.java‎

Copy file name to clipboard
+18Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.baeldung.maxdate;
2+
3+
import java.util.Date;
4+
5+
public class DateComparison {
6+
public int compareTodayWithMaxDate() {
7+
Date today = new Date();
8+
Date maxDate = new Date(Long.MAX_VALUE);
9+
10+
int comparisonResult = today.compareTo(maxDate);
11+
return comparisonResult;
12+
}
13+
14+
public static void main(String[] args) {
15+
DateComparison comparator = new DateComparison();
16+
System.out.println(comparator.compareTodayWithMaxDate());
17+
}
18+
}
Collapse file

‎core-java-modules/core-java-8-datetime-2/src/main/java/com/baeldung/maxdate/MaxDateDisplay.java‎

Copy file name to clipboard
+18Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.baeldung.maxdate;
2+
3+
import java.util.Date;
4+
import java.text.SimpleDateFormat;
5+
6+
public class MaxDateDisplay {
7+
public String getMaxDateValue() {
8+
Date maxDate = new Date(Long.MAX_VALUE);
9+
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
10+
return "The maximum date value in Java is: " + sdf.format(maxDate);
11+
}
12+
13+
public static void main(String[] args) {
14+
MaxDateDisplay display = new MaxDateDisplay();
15+
System.out.println(display.getMaxDateValue());
16+
}
17+
}
18+
Collapse file

‎core-java-modules/core-java-8-datetime-2/src/test/java/com/baeldung/maxdate/DateComparisonUnitTest.java‎

Copy file name to clipboard
+16Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.baeldung.maxdate;
2+
3+
import static org.junit.jupiter.api.Assertions.assertTrue;
4+
5+
import org.junit.jupiter.api.Test;
6+
7+
class DateComparisonUnitTest {
8+
9+
@Test
10+
void whenCompareTodayWithMaxDate_thenCorrectResult() {
11+
DateComparison comparator = new DateComparison();
12+
int result = comparator.compareTodayWithMaxDate();
13+
14+
assertTrue(result < 0);
15+
}
16+
}
Collapse file

‎core-java-modules/core-java-8-datetime-2/src/test/java/com/baeldung/maxdate/MaxDateDisplayUnitTest.java‎

Copy file name to clipboard
+18Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.baeldung.maxdate;
2+
3+
import static org.junit.jupiter.api.Assertions.assertEquals;
4+
5+
import org.junit.jupiter.api.Test;
6+
7+
class MaxDateDisplayUnitTest {
8+
9+
@Test
10+
void whenGetMaxDate_thenCorrectResult() {
11+
MaxDateDisplay display = new MaxDateDisplay();
12+
String result = display.getMaxDateValue();
13+
assertEquals(
14+
"The maximum date value in Java is: 292278994-08-17 07:12:55.807",
15+
result
16+
);
17+
}
18+
}

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.