How to format some date/time value


Dataweb project 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. 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)

Published in Mon, 27 December 2010 16:06