Start page / Template development / Template syntax / Data types / Date

Date data type

Value range of the Date data type

FirstSpirit provides the data type Date for the processing/editing of values which represent a date and/or a time. This data type enables interpretation of different date formats as Year, Month, Day, Hour, Minute and Second. The data type provides access to a range of methods which fall back on the calendar and relevant regional schema settings of the operating system (e.g. data formats) and therefore enable formatting in different, for example country-specific date formats and parsing.

The data type Date can also be looked up in the Sun API documentation:

java.util.Date

Definition

In FirstSpirit, when a date is defined a Date object of the class java.util.Date is generated. This data type is usually generated by means of the CMS_INPUT_DATE input component. Irrespective of this the .now method of the system object #global can be used to generate a new date object:

CMS_SET(myDate, #global.now)$

In this case the expression #global.now returns the current date.

Definition using the standard input components

Within the form area of a page or section template, input components are defined which can be subsequently used by the editors to insert the actual editorial contents into the page. The standard input components supported by FirstSpirit return different data types.

The following standard input components return an object of data type Date :

Then, with the help of a $CMS_VALUE(...)$ instruction, methods can then be applied to this object:

$CMS_VALUE(IDENTIFIER.METHOD)$

IDENTIFIER is the identifier defined in the resultname parameter of the input component.

Methods on date objects

The table below lists all methods which can be invoked on objects of data type Date.

The object is generated by the following form objects:
CMS_INPUT_DATE
Method name Return type Brief description Available since
after(Date) boolean
before(Date) boolean
compareTo(Date) int
compareTo(Object) int
equals(Object) boolean
from(Instant) Date
getClass Class Class of the invoking object
getTime long
hashCode int
isCase(Object) boolean
isNull boolean Checks whether an expression is null (zero)
print void
set(String, Object) Object
setTime(long) void
toInstant Instant
toJSON String Convert to a JSON-compatible string representation including necessary quotes and escaping for immediate use. Handles Maps, Collections, Arrays, Numbers, Strings, Boolean, Date, and JsonElement. A date instance will be converted to an ISO-8601 formatted date string. Any object other than above will be converted using its 'toString()' value. 5.2.11
toString String
type String

after(Date)

Method name Return type Available since
after(Date) boolean

before(Date)

Method name Return type Available since
before(Date) boolean

compareTo(Date)

Method name Return type Available since
compareTo(Date) int

compareTo(Object)

Method name Return type Available since
compareTo(Object) int

equals(Object)

Method name Return type Available since
equals(Object) boolean

from(Instant)

Method name Return type Available since
from(Instant) Date

getClass

The .getClass() (in Bean syntax: .class) method returns the class of the invoking object (cf. java.lang.Class).

Invocation:

$CMS_VALUE(myString.class)$
$CMS_VALUE(myString.getClass())$

Output:

java.lang.String
Method name Return type Available since
getClass Class

getTime

Method name Return type Available since
getTime long

hashCode

Method name Return type Available since
hashCode int

isCase(Object)

Method name Return type Available since
isCase(Object) boolean

isNull

The .isNull() (in Bean syntax: .isNull) method checks whether an expression or object is null , e.g. storeElement.isNull(). In the case of objects with complex values or objects, the object decides when it is null. The data type DomElement for example always contains an empty document, thus it is never null. For this reason, checking an empty DOM editor input component by using the method .isNull() returns the value false, whereas checking the component with .isEmpty() would return the value true.

The method .isNull() returns a Boolean value as the check result. true is the check result if the expression or object is null and false if not.

Method name Return type Available since
isNull boolean

print

Method name Return type Available since
print void

set(String, Object)

Method name Return type Available since
set(String, Object) Object

setTime(long)

Method name Return type Available since
setTime(long) void

toInstant

Method name Return type Available since
toInstant Instant

toJSON

Convert to a JSON-compatible string representation including necessary quotes and escaping for immediate use. Handles Maps, Collections, Arrays, Numbers, Strings, Boolean, Date, and JsonElement. A date instance will be converted to an ISO-8601 formatted date string. Any object other than above will be converted using its 'toString()' value.
Method name Return type Available since
toJSON String 5.2.11

toString

Method name Return type Available since
toString String

type

Method name Return type Available since
type String

© 2005 - 2024 Crownpeak Technology GmbH | All rights reserved. | FirstSpirit 2024.4 | Data privacy