Search code examples
javajsondategrailsgrails-orm

Save date in database in this format dd/MM/yy


Is it possible to save date values in the database of this format dd/MM/yy in Grails? I know I can customized the format in the views but I need the values to be returned as json and also return the values of dates in json in that format. Any suggestion will be appreciated.


Solution

  • Try this on your presentation layer, don't save time in that format in database. use following code to format the time according to your need.

        Date date = new Date( );
        SimpleDateFormat simpleFormat = new SimpleDateFormat ("dd/MM/yy"); 
        System.out.println("Date: " + simpleFormat .format(date));
    

    But if you want to save the data in this format in databse, then remember it returns a string and you will have to save the date in String format in database. Which I wouldn't recommend because of many reason.