Microsoft SDK for Java

DateDataFormat Class

The DateDataFormat class of the com.ms.wfc.data package represents a data format object for formatting date data types.

public class DateDataFormat extends DataFormat implements IConstructable 
{
  // Constructors

  public DateDataFormat(int format);

  public DateDataFormat(String customFormat);

  public DateDataFormat(int format, String customFormat);

  // Methods
  public String getCustomFormat();
  public int getFormat();
  public void setCustomFormat(String value);
  public void setFormat(int value);
}

Remarks

The Column and DataBinding classes provide a dataFormat property, which allows you to format numerical, date, or boolean values. For example, if a column in a DataGrid control contains dates or times, you can set its dataFormat property to a DateDataFormat object:

import com.ms.wfc.data.*;
import com.ms.wfc.data.ui.*;

/* Retrieve a date-valued column in a DataGrid control.
   Assume this column has an index of 1 in the grid. */
Column column1 = dataGrid1.getColumn(1);

/* Format the column by setting its dataFormat
   property. Create a DateDataFormat object and
   use the default Short Date format. */
column1.setDataFormat(new DateDataFormat());

The DateDataFormat class provides two fields to format date and time values as shown in the following table.

Property Description
format Specifies the type of format, using one of the constants from the DateFormat class. The default value of this property is DateFormat.SHORT, which specifies the Short Date format.
customFormat Specifies a custom format string, which is used only when the format property is set to DateFormat.CUSTOM.

The following example shows how to use these properties to change the initial format of the column:

/* Retrieve the column's current DateDataFormat object. */
DateDataFormat dFormat = (DateDataFormat) column1.getDataFormat();

/* Set the DateDataFormat object's format property
   to DateFormat.CUSTOM and set the customFormat
   property to a custom string. */ 
dFormat.setFormat(DateFormat.CUSTOM);
dFormat.setCustomFormat("mm/dd/yyyy");

For information about formatting date or time values in the Forms Designer, see Formatting Data.

See Also   BooleanDataFormat, NumberDataFormat

© 1999 Microsoft Corporation. All rights reserved. Terms of use.