com.smartgwt.client.util
Class DateUtil

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

public class DateUtil
extends 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 setDefaultDisplayTimezone(String offset)
          Globally sets the offset from UTC to use when formatting values of type datetime and time with standard display formatters.
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

setDefaultDisplayTimezone

public static void setDefaultDisplayTimezone(String offset)
Globally sets the offset from UTC to use when formatting values of type datetime and time with standard display formatters. If this method is never called, the default display timezone for times and datetimes will be derived from the native browser local timezone.

Parameters:
offset - offset from UTC. This should be a string in the format +/-HH:MM for example "-08:00"

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