SUI.date

The SUI.date namespace contains a set of utility functions for working with dates.

The JavaScript Date object gives us a lot of functionality, but since we'll be working with SQL type dates (YYYY-MM-DD HH:II:SS) a lot this namespace contains a minimal set of utility functions for conversions between SQL date strings and JavaScript Date objects

Defined in: date.js


Method summary

Attr. Type Name / Description
public String

format(dt, format)

Format a JavaScript Date object according to the locale or format string.

public String

padZero(v, n)

Create a zero padded string for date displaying.

public Date

parseSqlDate(d)

Parse an SQL date string into a JavaScript Date object.

public String

toSqlDate(dt, timestamp)

Create an SQL date string from an JavaScript Date object.

 


Methods

public String format( Date dt, String format)

Format a JavaScript Date object according to the locale or format string.

Parameters:

Name Type Description
Date dt A JavaScript Date object for which to create a string representation.
String format A date format string. possible values: date (default)/time/datetime (format according to the locale) or a format string containing the following letters: d,m,y,h,i,s

Returns:

String The given date in the requested format.

public String padZero( int v, int n)

Create a zero padded string for date displaying.

Parameters:

Name Type Description
int v The number to pad the zeros to.
int n The maximum length of the result string (defaults to 2).

Returns:

String A zero padded string.

public Date parseSqlDate( String d)

Parse an SQL date string into a JavaScript Date object.

Parameters:

Name Type Description
String d A string in SQL date format (date or timestamp)

Returns:

Date A JavaScript Date object

public String toSqlDate( Date dt, boolean timestamp)

Create an SQL date string from an JavaScript Date object.

Parameters:

Name Type Description
Date dt A JavaScript Date to format as a SQL date string
boolean timestamp Return the value as SQL date (default) or SQL timestamp

Returns:

String An date string in SQL format.