Java examples for java.util:Date Format
Format date To String in yyyy-MM-dd HH:mm format
//package com.java2s; import java.text.SimpleDateFormat; import java.util.Date; public class Main { public static void main(String[] argv) { Date date = new Date(); String pattern = "yyyy-MM-dd HH:mm"; System.out.println(dateToString(date, pattern)); }/* ww w .j a va2 s . c om*/ public static String dateToString(Date date, String pattern) { SimpleDateFormat sdf = new SimpleDateFormat(pattern); return sdf.format(date); } }