Take a look at [Java SimpleDateFormat](http://docs.oracle.com/javase/6/docs/api/java/text/SimpleDateFormat.html).

    system.debug(Datetime.now().format('hh:mm:ss aa')); // 08:24:07 AM 
    system.debug(Datetime.now().format('yyyy-MM-dd'));  // 2016-05-31