Example usage for java.text SimpleDateFormat format

List of usage examples for java.text SimpleDateFormat format

Introduction

In this page you can find the example usage for java.text SimpleDateFormat format.

Prototype

public final String format(Date date) 

Source Link

Document

Formats a Date into a date-time string.

Usage

From source file:Main.java

public static void main(String[] args) throws ParseException {
    SimpleDateFormat inFormat = new SimpleDateFormat("yyyy-MM-dd-'T'HH:mm:ss'Z'");
    Date inDate = inFormat.parse("2015-01-11-T00:00:00Z");

    SimpleDateFormat outFormat = new SimpleDateFormat("yyyyMMdd");
    String output = outFormat.format(inDate);

    System.out.println("Date: " + output);

}

From source file:Main.java

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);/*  www.j a  v a  2 s . c  o m*/
    System.out.println("formatted date in dd/MM/yyyy : " + strDate);

}

From source file:Main.java

public static void main(String args[]) {
    Date date = new Date();
    String DATE_FORMAT = "MM/dd/yyyy";
    SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT);
    System.out.println("Today is " + sdf.format(date));
}

From source file:Main.java

public static void main(String[] args) {
    Calendar cal = Calendar.getInstance();
    System.out.println("Calendar:" + cal.toString());
    Date d = cal.getTime();/*w  w  w  . j a  v a 2 s  .c o  m*/
    SimpleDateFormat sdf = new SimpleDateFormat("DD/MM/yyyy HH:mm:ss");
    System.out.println(sdf.format(d));
    SimpleDateFormat sdfNew = new SimpleDateFormat("HH:mm:ss");
    System.out.println(sdfNew.format(d));
}

From source file:Main.java

public static void main(String[] args) {
    GregorianCalendar gc = new GregorianCalendar(2010, Calendar.SEPTEMBER, 9);
    Date birthDate = gc.getTime();

    String pattern = "'I was born on the day' dd 'of the month 'MMMM 'in' yyyy";

    SimpleDateFormat simpleFormatter = new SimpleDateFormat(pattern);
    System.out.println(simpleFormatter.format(birthDate));
}

From source file:Main.java

public static void main(String[] args) {
    Date date = new Date();

    SimpleDateFormat sdf = new SimpleDateFormat("H");
    System.out.println("hour in H format : " + sdf.format(date));
}

From source file:Main.java

public static void main(String[] args) {
    Date date = new Date();

    SimpleDateFormat sdf = new SimpleDateFormat("K");
    System.out.println("hour in K format : " + sdf.format(date));
}

From source file:Main.java

public static void main(String[] args) {
    Date date = new Date();

    SimpleDateFormat sdf = new SimpleDateFormat("k");
    System.out.println("hour in k format : " + sdf.format(date));
}

From source file:DateFormatApp.java

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

From source file:Main.java

public static void main(String[] args) {
    Date date = new Date();

    SimpleDateFormat sdf = new SimpleDateFormat("kk");
    System.out.println("hour in kk format : " + sdf.format(date));
}