Class Dates

java.lang.Object
se.datadosen.util.Dates

public class Dates
extends java.lang.Object
Utility class to simplify date display and date arithmetic
  • Method Summary

    Modifier and Type Method Description
    static int dateDiff​(char unit, java.lang.String testDate, java.lang.String refDate)
    Return difference between two dates in the unit specified by unit
    static int dateDiff​(char unit, java.lang.String testDate, java.util.Date refDate)
    Return difference between two dates in the unit specified by unit
    static int dateDiff​(char unit, java.util.Date testDate, java.lang.String refDate)
    Return difference between two dates in the unit specified by unit
    static int dateDiff​(char unit, java.util.Date testDate, java.util.Date refDate)
    Return difference between two dates in the unit specified by unit
    static java.lang.String format​(long date)
    Return a date formatted according to the default date pattern
    static java.lang.String format​(long date, java.lang.String pattern)
    Return a date formatted according to the given date pattern
    static java.lang.String format​(java.lang.String dateString)
    Return a date formatted according to the default date pattern
    static java.lang.String format​(java.lang.String dateString, java.lang.String pattern)
    Return a date formatted according to the given date pattern
    static java.lang.String format​(java.util.Date date)
    Return a date formatted according to the default date pattern
    static java.lang.String format​(java.util.Date date, java.lang.String pattern)
    Return a date formatted according to the given date pattern
    static java.util.Date now()
    Get Date object representing now
    static java.lang.String stripTime​(java.lang.String pattern)
    Strip the time portion from date pattern strings
    static java.util.Date toDate​(long dateMillis)
    Return a date object from milliseconds since epoch
    static java.util.Date toDate​(java.lang.String dateString)
    Return a date object from a string

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • now

      public static java.util.Date now()
      Get Date object representing now
      Returns:
    • format

      public static java.lang.String format​(java.util.Date date)
      Return a date formatted according to the default date pattern
      Parameters:
      date -
      Returns:
    • format

      public static java.lang.String format​(long date)
      Return a date formatted according to the default date pattern
      Parameters:
      date -
      Returns:
      Since:
      21.1
    • format

      public static java.lang.String format​(java.lang.String dateString)
      Return a date formatted according to the default date pattern
      Parameters:
      dateString -
      Returns:
    • format

      public static java.lang.String format​(java.util.Date date, java.lang.String pattern)
      Return a date formatted according to the given date pattern
      Parameters:
      date -
      pattern -
      Returns:
    • format

      public static java.lang.String format​(long date, java.lang.String pattern)
      Return a date formatted according to the given date pattern
      Parameters:
      date -
      pattern -
      Returns:
      Since:
      21.1
    • format

      public static java.lang.String format​(java.lang.String dateString, java.lang.String pattern)
      Return a date formatted according to the given date pattern
      Parameters:
      dateString -
      pattern -
      Returns:
    • toDate

      public static java.util.Date toDate​(java.lang.String dateString)
      Return a date object from a string
      Parameters:
      dateString -
      Returns:
    • toDate

      public static java.util.Date toDate​(long dateMillis)
      Return a date object from milliseconds since epoch
      Parameters:
      dateMillis -
      Returns:
    • dateDiff

      public static int dateDiff​(char unit, java.util.Date testDate, java.util.Date refDate) throws java.lang.IllegalArgumentException
      Return difference between two dates in the unit specified by unit
      Parameters:
      unit - 'D' for day difference
      testDate -
      refDate -
      Returns:
      Throws:
      java.lang.IllegalArgumentException
    • dateDiff

      public static int dateDiff​(char unit, java.lang.String testDate, java.util.Date refDate) throws java.lang.IllegalArgumentException
      Return difference between two dates in the unit specified by unit
      Parameters:
      unit - 'D' for day difference
      testDate -
      refDate -
      Returns:
      Throws:
      java.lang.IllegalArgumentException
    • dateDiff

      public static int dateDiff​(char unit, java.util.Date testDate, java.lang.String refDate) throws java.lang.IllegalArgumentException
      Return difference between two dates in the unit specified by unit
      Parameters:
      unit - 'D' for day difference
      testDate -
      refDate -
      Returns:
      Throws:
      java.lang.IllegalArgumentException
    • dateDiff

      public static int dateDiff​(char unit, java.lang.String testDate, java.lang.String refDate) throws java.lang.IllegalArgumentException
      Return difference between two dates in the unit specified by unit
      Parameters:
      unit - 'D' for day difference
      testDate -
      refDate -
      Returns:
      Throws:
      java.lang.IllegalArgumentException
    • stripTime

      public static java.lang.String stripTime​(java.lang.String pattern)
      Strip the time portion from date pattern strings
      Parameters:
      pattern - Any date pattern. Pass empty string to use default locale's pattern
      Returns:
      Date pattern string without time portion
      Since:
      22.0.3