Format date in dd/mm/yyyy format : SimpleDateFormat « Development « Java Tutorial

import java.util.Date;

import java.text.SimpleDateFormat;

public class Main {

  public static void main(String[] args) {
    Date date = new Date();
    SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yy");

    String strDate = sdf.format(date);
    System.out.println("formatted date in mm/dd/yy : " + strDate);

    sdf = new SimpleDateFormat("dd/MM/yyyy");
    strDate = sdf.format(date);
    System.out.println("formatted date in dd/MM/yyyy : " + strDate);


6.12.1.Get Today's Date SimpleDateFormat('hh') SimpleDateFormat('H') // The hour (0-23) SimpleDateFormat('m'): The minutes SimpleDateFormat('mm') SimpleDateFormat('s'): The seconds SimpleDateFormat('ss') SimpleDateFormat('a'): The am/pm marker SimpleDateFormat('z'): The time zone SimpleDateFormat('zzzz') SimpleDateFormat('Z') SimpleDateFormat('hh:mm:ss a') SimpleDateFormat('') SimpleDateFormat('HH:mm:ss Z')
6.12.15.The day number: SimpleDateFormat('d')
6.12.16.Two digits day number: SimpleDateFormat('dd')
6.12.17.The day in week: SimpleDateFormat('E')
6.12.18.Full day name: SimpleDateFormat('EEEE')
6.12.19.SimpleDateFormat('MM'): number based month value
6.12.22.The month: SimpleDateFormat('M')
6.12.23.SimpleDateFormat('E, dd MMM yyyy HH:mm:ss Z')
6.12.25.Three letter-month value: SimpleDateFormat('MMM')
6.12.26.Full length of month name: SimpleDateFormat('MMMM')
6.12.27.Formatting a Date Using a Custom Format
6.12.28.Formatting date with full day and month name and show time up to milliseconds with AM/PM
6.12.29.Format date in dd/mm/yyyy format
6.12.30.Format date in mm-dd-yyyy hh:mm:ss format
6.12.31.Formatting day of week using SimpleDateFormat
6.12.32.Formatting day of week in EEEE format like Sunday, Monday etc.
6.12.33.Formatting day in d format like 1,2 etc
6.12.34.Formatting day in dd format like 01, 02 etc.
6.12.35.Format hour in h (1-12 in AM/PM) format like 1, 2..12.
6.12.36.Format hour in hh (01-12 in AM/PM) format like 01, 02..12.
6.12.37.Format hour in H (0-23) format like 0, 1...23.
6.12.38.Format hour in HH (00-23) format like 00, 01..23.
6.12.39.Format hour in k (1-24) format like 1, 2..24.
6.12.40.Format hour in kk (01-24) format like 01, 02..24.
6.12.41.Format hour in K (0-11 in AM/PM) format like 0, 1..11.
6.12.42.Format hour in KK (00-11) format like 00, 01,..11.
6.12.43.Formatting minute in m format like 1,2 etc.
6.12.44.Format minutes in mm format like 01, 02 etc.
6.12.45.Format month in M format like 1,2 etc
6.12.46.Format Month in MM format like 01, 02 etc.
6.12.47.Format Month in MMM format like Jan, Feb etc.
6.12.48.Format Month in MMMM format like January, February etc.
6.12.49.Format seconds in s format like 1,2 etc.
6.12.50.Format seconds in ss format like 01, 02 etc.
6.12.51.Format TimeZone in z (General time zone) format like EST.
6.12.52.Format TimeZone in zzzz format Eastern Standard Time.
6.12.53.Format TimeZone in Z (RFC 822) format like -8000.
6.12.54.Format year in yy format like 07, 08 etc
6.12.55.Format year in yyyy format like 2007, 2008 etc.
6.12.56.Parsing custom formatted date string into Date object using SimpleDateFormat
6.12.57.Date Formatting and Localization
6.12.58.Add AM PM to time using SimpleDateFormat
6.12.59.Check if a String is a valid date