Cookbook
Date Formatting PDF Print E-mail

Recipe: I want to format some date/time value

DataWeb framework uses BeanShell as scripting language which in turn is a simplified Java. Date/Time formatting in Java is not as straight forward as other languages but DataWeb has implemented a simple way to manage with this kind of objects:

As you have learned, whenever you have a table column with type DateTime you should provide a format pattern. The same notation could be used by code like the example below (supposing you are in a Form):

var Dta = dataweb.util.DataFormatter.format(dataweb.util.DateTimeUtil.getDate(), "DateTime:dd/MM/yyyy", thisForm.getLocale());

dataweb.util.DataFormatter.format - this static function does the magic
dataweb.util.DateTimeUtil.getDate() - this one get current Date (you could ask getTime() for time or even getDateTime())
DateTime:dd/MM/yyyy - this is the required format as for table columns
thisForm.getLocale() - this is the Locale used in the Form (you could specify the required one)