Format date in Long custom date format in Java

Description

The following code shows how to format date in Long custom date format.

Example


/*from  ww  w .j  av  a  2 s  . co  m*/
import java.text.SimpleDateFormat;
import java.util.Date;

public class Main {
  public static void main(String args[]) {
    String pattern = "'The year is '";
    pattern += "yyyy GG";
    pattern += "'.\nThe month is '";
    pattern += "MMMMMMMMM";
    pattern += "'.\nIt is '";
    pattern += "hh";
    pattern += "' o''clock '";
    pattern += "a, zzzz";
    pattern += "'.'";
    SimpleDateFormat format = new SimpleDateFormat(pattern);
    String formattedDate = format.format(new Date());
    System.out.println(formattedDate);
  }
}

The code above generates the following result.





















Home »
  Java Tutorial »
    Date »




Date Get
Date Set
Date Format
Date Compare
Date Convert
Date Calculation
Date Parse
Timezone