Format date To String in yyyy-MM-dd HH:mm format - Java java.util

Java examples for java.util:Date Format

Description

Format date To String in yyyy-MM-dd HH:mm format

Demo Code


//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);
    }
}

Related Tutorials