The DateFormat class can be used to parse a string representing a date, time, or the combination of date and time into a JavaScript date object and vice versa (also known as format).
The format pattern must be defined in Locale Data Markup Language (LDML) date format notation. The following options are available:
style: Can be "short", "medium", "long" or "full" and will use a locale dependent pattern
pattern: A date pattern in LDML date format notation
If both, style and pattern, are defined, the pattern is used and the style ignored.
The following code snippet shows an example how the DateFormat class can be used:
#!jsjQuery.sap.require("sap.ui.core.format.DateFormat"); var oDateFormat = sap.ui.core.format.DateFormat.getDateTimeInstance({pattern: "dd/MM/yyyy HH:mm"}); //Returns a DateFormat instance for date and time //var oDateFormat = sap.ui.core.format.DateFormat.getInstance({pattern: "dd/MM/yyyy"}); //Returns a DateFormat instance for date //var oDateFormat = sap.ui.core.format.DateFormat.getTimeInstance({pattern: "HH:mm"}); //Returns a DateFormat instance for time var oField = new sap.ui.commons.TextField(); oField.setValue(oDateFormat.format(oDate)); // Set the formatted value on the text field oField.attachChange(function(){ //Parse the user input oDate = oDateFormat.parse(oField.getValue()); });