logo

Formats a Date object into a string yyyy-MM-dd HH:mm:ss

Java Code Examples for java.text.SimpleDateFormat.format()

Formats a Date into a string yyyy-MM-dd HH:mm:ss.

package simplesolution.dev;

import java.text.SimpleDateFormat;
import java.util.Date;

public class SimpleDateFormatFormatExamples {

    public static void main(String... args) {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date dateToFormat = new Date();
        String formattedValue = simpleDateFormat.format(dateToFormat);

        System.out.println(formattedValue);
    }
}

Happy Coding 😊