com.smartgwt.client.util
Class DateUtil

java.lang.Object
  extended by com.smartgwt.client.util.DateUtil

public class DateUtil
extends java.lang.Object

Date related utility methods.


Constructor Summary
DateUtil()
           
 
Method Summary
static void setDateInputFormatter(DateInputFormatter formatter)
          Sets up the default format for strings being parsed into dates via Date.parseInput
Sample code :
static void setNormalDateDisplayFormat(DateDisplayFormat format)
          Set the default formatter for date objects to the method name passed in.
static void setNormalDateDisplayFormatter(DateDisplayFormatter formatter)
          Set the default formatter for date objects to the method name passed in.
static void setShortDateDisplayFormat(DateDisplayFormat format)
          Set the default formatter for date objects to the method name passed in.
static void setShortDateDisplayFormatter(DateDisplayFormatter formatter)
          Set the default formatter for date objects to the method name passed in.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DateUtil

public DateUtil()
Method Detail

setNormalDateDisplayFormat

public static void setNormalDateDisplayFormat(DateDisplayFormat format)
Set the default formatter for date objects to the method name passed in. After calling this method, subsequent calls to Date.toNormalDate will return a string formatted according to this format specification.
Note: this will be the standard long date format used by SmartGWT components. Initial default normalDisplayFormat is "toLocaleString"

Parameters:
format - the DateDisplayFormat

setNormalDateDisplayFormatter

public static void setNormalDateDisplayFormatter(DateDisplayFormatter formatter)
Set the default formatter for date objects to the method name passed in. After calling this method, subsequent calls to Date.toNormalDate will return a string formatted according to this format specification.
Note: this will be the standard long date format used by SmartGWT components. The DateDisplayFormatter function will be executed in the scope of the Date and should return the formatted string.

Initial default normalDisplayFormat is "toLocaleString"

 DateUtil.setNormalDateDisplayFormatter(new DateDisplayFormatter() {
     public String format(Date date) {
         if(date == null) return null;
         final DateTimeFormat dateFormatter = DateTimeFormat.getFormat("yyyy.MM.dd HH:mm:ss");
         String format = dateFormatter.format(date);
         return format;
     }
 });
 

Parameters:
formatter - the DateDisplayFormatter

setShortDateDisplayFormat

public static void setShortDateDisplayFormat(DateDisplayFormat format)
Set the default formatter for date objects to the method name passed in. After calling this method, subsequent calls to Date.toShortDate will return a string formatted according to this format specification.
Note: this will be the standard long date format used by SmartGWT components. Initial default normalDisplayFormat is "toUSShortDate"

Parameters:
format - the DateDisplayFormat

setShortDateDisplayFormatter

public static void setShortDateDisplayFormatter(DateDisplayFormatter formatter)
Set the default formatter for date objects to the method name passed in. After calling this method, subsequent calls to Date.toShortDate will return a string formatted according to this format specification.
Note: this will be the standard long date format used by SmartGWT components. The DateDisplayFormatter function will be executed in the scope of the Date and should return the formatted string.

Initial default normalDisplayFormat is "toUSShortDate" Sample code :

 DateUtil.setShortDateDisplayFormatter(new DateDisplayFormatter() {
     public String format(Date date) {
         if(date == null) return null;
         final DateTimeFormat dateFormatter = DateTimeFormat.getFormat("MMM d, yyyy");
         String format = dateFormatter.format(date);
         return format;
     }
 });
 

Parameters:
formatter - the DateDisplayFormatter

setDateInputFormatter

public static void setDateInputFormatter(DateInputFormatter formatter)
Sets up the default format for strings being parsed into dates via Date.parseInput
Sample code :
 DateUtil.setDateInputFormatter(new DateInputFormatter() {
    public Date format(String dateString) {
       final DateTimeFormat dateFormatter = DateTimeFormat.getFormat("MMM d, yyyy");
       Date date = dateFormatter.parse(dateString);
       return date;
    }
 });
 

Parameters:
formatter - the DateInputFormatter