Java Data Type How to - Format date time as '22-06-15 14:25:36'


We would like to know how to format date time as '22-06-15 14:25:36'.


import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
/*from   w ww.jav a 2s.  c o  m*/
public class Main {

  public static void main(String[] args) {
    LocalDateTime now =;
    System.out.println(now.format(DateTimeFormatter.ofPattern("dd-MM-yy HH:mm:ss")));

The code above generates the following result.