DateFormat is a specific class for formatting and parsing dates in a locale-sensitive manner. It allows for formatting (date -> text), parsing (text -> date), and normalization.

DateFormat is a static class based on Java SimpleDataFormat. It must not be initialized and it's methods must be used statically.

1 Date format

You can use Ax.text.DateFormat.format method to format a date variable to a formatted string. Take into account that native JS Dates cannot be passed directly as parameter and you need to convert it to milliseconds.

Copy
<script>
    console.log(Ax.text.DateFormat.format(new Date().getTime(), "dd-MM-yyyy"));
    
    console.log(Ax.text.DateFormat.format(new Date().getTime(), "dd-MM-yyyy HH:mm"));
    
    var m_row = Ax.db.executeQuery("SELECT CURRENT AS curdate FROM systables WHERE tabid = 1").toOne();
    console.log(Ax.text.DateFormat.format(m_row.curdate, "dd-MM-yyyy HH:mm"));
    
    var m_row = Ax.db.executeQuery("SELECT TODAY AS curdate FROM systables WHERE tabid = 1").toOne();
    console.log(Ax.text.DateFormat.format(m_row.curdate, "dd-MM-yyyy HH:mm"));
</script>
14-01-2019
14-01-2019 17:38
14-01-2019 17:38
14-01-2019 00:00

2 Date parse

Copy
<script>
    var m_date = Ax.text.DateFormat.parse("10-05-2019", "dd-MM-yyyy");
    console.log(m_date);
    console.log("Year : " + (m_date.getYear() + 1900));
    console.log("Month: " + m_date.getMonth());
    console.log("Day  : " + m_date.getDay());
</script>
Fri May 10 00:00:00 CEST 2019
Year : 2019
Month: 4
Day  : 5