Class UtilDateTime

java.lang.Object
org.ofbiz.core.util.UtilDateTime

public class UtilDateTime extends Object
Utility class for handling java.util.Date, the java.sql data/time classes and related information
Since:
2.0
Version:
$Revision: 1.1 $
Author:
David E. Jones, Andy Zeneski
  • Constructor Details

    • UtilDateTime

      public UtilDateTime()
  • Method Details

    • nowTimestamp

      public static Timestamp nowTimestamp()
      Return a Timestamp for right now
      Returns:
      Timestamp for right now
    • nowDate

      public static Date nowDate()
      Return a Date for right now
      Returns:
      Date for right now
    • getDayStart

      public static Timestamp getDayStart(Timestamp stamp)
    • getDayStart

      public static Timestamp getDayStart(Timestamp stamp, int daysLater)
    • getNextDayStart

      public static Timestamp getNextDayStart(Timestamp stamp)
    • getDayEnd

      public static Timestamp getDayEnd(Timestamp stamp)
    • getDayEnd

      public static Timestamp getDayEnd(Timestamp stamp, int daysLater)
    • toSqlDate

      public static Date toSqlDate(String date)
      Converts a date String into a java.sql.Date
      Parameters:
      date - The date String: MM/DD/YYYY
      Returns:
      A java.sql.Date made from the date String
    • toSqlDate

      public static Date toSqlDate(String monthStr, String dayStr, String yearStr)
      Makes a java.sql.Date from separate Strings for month, day, year
      Parameters:
      monthStr - The month String
      dayStr - The day String
      yearStr - The year String
      Returns:
      A java.sql.Date made from separate Strings for month, day, year
    • toSqlDate

      public static Date toSqlDate(int month, int day, int year)
      Makes a java.sql.Date from separate ints for month, day, year
      Parameters:
      month - The month int
      day - The day int
      year - The year int
      Returns:
      A java.sql.Date made from separate ints for month, day, year
    • toSqlTime

      public static Time toSqlTime(String time)
      Converts a time String into a java.sql.Time
      Parameters:
      time - The time String: either HH:MM or HH:MM:SS
      Returns:
      A java.sql.Time made from the time String
    • toSqlTime

      public static Time toSqlTime(String hourStr, String minuteStr, String secondStr)
      Makes a java.sql.Time from separate Strings for hour, minute, and second.
      Parameters:
      hourStr - The hour String
      minuteStr - The minute String
      secondStr - The second String
      Returns:
      A java.sql.Time made from separate Strings for hour, minute, and second.
    • toSqlTime

      public static Time toSqlTime(int hour, int minute, int second)
      Makes a java.sql.Time from separate ints for hour, minute, and second.
      Parameters:
      hour - The hour int
      minute - The minute int
      second - The second int
      Returns:
      A java.sql.Time made from separate ints for hour, minute, and second.
    • toTimestamp

      public static Timestamp toTimestamp(String dateTime)
      Converts a date and time String into a Timestamp
      Parameters:
      dateTime - A combined data and time string in the format "MM/DD/YYYY HH:MM:SS", the seconds are optional
      Returns:
      The corresponding Timestamp
    • toTimestamp

      public static Timestamp toTimestamp(String date, String time)
      Converts a date String and a time String into a Timestamp
      Parameters:
      date - The date String: MM/DD/YYYY
      time - The time String: either HH:MM or HH:MM:SS
      Returns:
      A Timestamp made from the date and time Strings
    • toTimestamp

      public static Timestamp toTimestamp(String monthStr, String dayStr, String yearStr, String hourStr, String minuteStr, String secondStr)
      Makes a Timestamp from separate Strings for month, day, year, hour, minute, and second.
      Parameters:
      monthStr - The month String
      dayStr - The day String
      yearStr - The year String
      hourStr - The hour String
      minuteStr - The minute String
      secondStr - The second String
      Returns:
      A Timestamp made from separate Strings for month, day, year, hour, minute, and second.
    • toTimestamp

      public static Timestamp toTimestamp(int month, int day, int year, int hour, int minute, int second)
      Makes a Timestamp from separate ints for month, day, year, hour, minute, and second.
      Parameters:
      month - The month int
      day - The day int
      year - The year int
      hour - The hour int
      minute - The minute int
      second - The second int
      Returns:
      A Timestamp made from separate ints for month, day, year, hour, minute, and second.
    • toDate

      public static Date toDate(String dateTime)
      Converts a date and time String into a Date
      Parameters:
      dateTime - A combined data and time string in the format "MM/DD/YYYY HH:MM:SS", the seconds are optional
      Returns:
      The corresponding Date
    • toDate

      public static Date toDate(String date, String time)
      Converts a date String and a time String into a Date
      Parameters:
      date - The date String: MM/DD/YYYY
      time - The time String: either HH:MM or HH:MM:SS
      Returns:
      A Date made from the date and time Strings
    • toDate

      public static Date toDate(String monthStr, String dayStr, String yearStr, String hourStr, String minuteStr, String secondStr)
      Makes a Date from separate Strings for month, day, year, hour, minute, and second.
      Parameters:
      monthStr - The month String
      dayStr - The day String
      yearStr - The year String
      hourStr - The hour String
      minuteStr - The minute String
      secondStr - The second String
      Returns:
      A Date made from separate Strings for month, day, year, hour, minute, and second.
    • toDate

      public static Date toDate(int month, int day, int year, int hour, int minute, int second)
      Makes a Date from separate ints for month, day, year, hour, minute, and second.
      Parameters:
      month - The month int
      day - The day int
      year - The year int
      hour - The hour int
      minute - The minute int
      second - The second int
      Returns:
      A Date made from separate ints for month, day, year, hour, minute, and second.
    • toDateString

      public static String toDateString(Date date)
      Makes a date String in the format MM/DD/YYYY from a Date
      Parameters:
      date - The Date
      Returns:
      A date String in the format MM/DD/YYYY
    • toTimeString

      public static String toTimeString(Date date)
      Makes a time String in the format HH:MM:SS from a Date. If the seconds are 0, then the output is in HH:MM.
      Parameters:
      date - The Date
      Returns:
      A time String in the format HH:MM:SS or HH:MM
    • toTimeString

      public static String toTimeString(int hour, int minute, int second)
      Makes a time String in the format HH:MM:SS from a separate ints for hour, minute, and second. If the seconds are 0, then the output is in HH:MM.
      Parameters:
      hour - The hour int
      minute - The minute int
      second - The second int
      Returns:
      A time String in the format HH:MM:SS or HH:MM
    • toDateTimeString

      public static String toDateTimeString(Date date)
      Makes a combined data and time string in the format "MM/DD/YYYY HH:MM:SS" from a Date. If the seconds are 0 they are left off.
      Parameters:
      date - The Date
      Returns:
      A combined data and time string in the format "MM/DD/YYYY HH:MM:SS" where the seconds are left off if they are 0.
    • monthBegin

      public static Timestamp monthBegin()
      Makes a Timestamp for the beginning of the month
      Returns:
      A Timestamp of the beginning of the month