Write a program to format DateTime


public class Main {
    public static void main(String[] args) {
        String format = "dd-MM-yyyy hh:mm:ss aa";
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat(format); //passing format as constructor
        String date = simpleDateFormat.format(new Date());
        System.out.println(date);

    }
}
Output:
12-12-2020 04:06:07 PM
about author

admin

salmansrabon@gmail.com

If you like my post or If you have any queries, do not hesitate to leave a comment.

Leave a Reply

Your email address will not be published. Required fields are marked *