[]
        
(Showing Draft Content)

DateInfo

Class DateInfo

java.lang.Object
com.grapecity.documents.excel.DateInfo

public final class DateInfo extends Object
Provides helper methods for converting between OADate values and Java date-time types.

Use this type when you need to exchange date values between Java code and the numeric date representation used by Excel and OLE Automation.


 LocalDateTime appointment = LocalDateTime.of(2024, 1, 15, 8, 30);
 double oaDate = DateInfo.ToOADate(appointment);
 LocalDateTime restored = DateInfo.FromOADateAsLocalDateTime(oaDate);
 
  • Constructor Details

    • DateInfo

      public DateInfo()
  • Method Details

    • ToOADate

      public static double ToOADate(Date date)
      Gets the OADate value for a Date.

      Use this method to convert a Java Date value to the numeric date representation used by Excel and OLE Automation.

      
       Calendar calendar = new GregorianCalendar(2024, Calendar.JANUARY, 15, 8, 30, 0);
       Date date = calendar.getTime();
       double oaDate = DateInfo.ToOADate(date);
       
      Parameters:
      date - The Date object to convert.
      Returns:
      The OADate value that corresponds to the specified Date.
    • ToOADate

      public static double ToOADate(Calendar calendar)
      Gets the OADate value according to a Calendar.

      Use this method to convert a Java calendar value to the numeric date representation used by Excel.

      
       Calendar calendar = Calendar.getInstance();
       calendar.set(2024, Calendar.JANUARY, 15, 8, 30, 0);
       calendar.set(Calendar.MILLISECOND, 0);
       double oaDate = DateInfo.ToOADate(calendar);
       
      Parameters:
      calendar - The Calendar object to convert.
      Returns:
      The value of OADate.
    • ToOADate

      public static double ToOADate(LocalDateTime localDateTime)
      Gets the OADate value according to a LocalDateTime.

      Use this method to convert a Java date-time value to the numeric date representation used by Excel.

      
       LocalDateTime localDateTime = LocalDateTime.of(2024, 1, 15, 8, 30);
       double oaDate = DateInfo.ToOADate(localDateTime);
       
      Parameters:
      localDateTime - The LocalDateTime object to convert.
      Returns:
      The value of OADate.
    • FromOADate

      @Deprecated public static Date FromOADate(double value)
      Deprecated.
      Converts an OADate value to a Date.

      This method returns the Date that corresponds to the specified OADate value.

      Parameters:
      value - The OADate value to convert.
      Returns:
      The Date that corresponds to the specified OADate value.
    • FromOADateAsLocalDateTime

      public static LocalDateTime FromOADateAsLocalDateTime(double value)
      Gets a LocalDateTime according to an OADate value.

      Use this method to convert an OLE Automation date value to a LocalDateTime. To convert a LocalDateTime back to an OADate value, use ToOADate(LocalDateTime).

      
       double oaDate = 45292.5;
       LocalDateTime dateTime = DateInfo.FromOADateAsLocalDateTime(oaDate);
       int hour = dateTime.getHour();
       
      Parameters:
      value - The OADate value to convert.
      Returns:
      The corresponding LocalDateTime.