Example usage for java.text SimpleDateFormat SimpleDateFormat

List of usage examples for java.text SimpleDateFormat SimpleDateFormat

Introduction

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

Prototype

public SimpleDateFormat(String pattern) 

Source Link

Document

Constructs a SimpleDateFormat using the given pattern and the default date format symbols for the default java.util.Locale.Category#FORMAT FORMAT locale.

Usage

From source file:Main.java

public static void main(String[] args) {
    SimpleDateFormat simpleFormatter = new SimpleDateFormat("dd/MM/yyyy");
    Date today = new Date();
    String formattedDate = simpleFormatter.format(today);
    System.out.println("Today is (dd/MM/yyyy):  " + formattedDate);

    simpleFormatter.applyPattern("MMMM dd, yyyy");
    formattedDate = simpleFormatter.format(today);
    System.out.println("Today is  (MMMM dd, yyyy): " + formattedDate);
}

From source file:Main.java

public static void main(String[] args) throws Throwable {
    SimpleDateFormat format = new SimpleDateFormat("HH:mm:ss");
    Date date1 = format.parse("08:00:01");
    Date date2 = format.parse("23:00:05");
    Date date = new Date(date2.getTime() - date1.getTime());
    System.out.println(format.format(date));
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    SimpleDateFormat sdfSource = new SimpleDateFormat("dd/MM/yy");
    Date date = sdfSource.parse("12/11/09");
    SimpleDateFormat sdfDestination = new SimpleDateFormat("MM-dd-yyyy hh:mm:ss");
    System.out.println(sdfDestination.format(date));
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    SimpleDateFormat sdf = new SimpleDateFormat("dd MM yyyy");
    Date dt1 = sdf.parse("22 02 2000");

    Date dt2 = sdf.parse("22 02 2010");

    long diff = dt2.getTime() - dt1.getTime();

    System.out.println("Days: " + diff / 1000L / 60L / 60L / 24L);
}

From source file:Main.java

public static void main(String[] args) throws Exception {

    SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");

    Date theDate = dateFormat.parse("01/01/2009");
    System.out.println(dateFormat.format(theDate));

}

From source file:Main.java

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

    SimpleDateFormat sdf = new SimpleDateFormat("MM");
    System.out.println("Current Month in MM format : " + sdf.format(date));
}

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("kk");
    System.out.println("hour in kk format : " + sdf.format(date));
}

From source file:Main.java

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

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

From source file:Main.java

public static void main(String[] args) throws ParseException {

    SimpleDateFormat in = new SimpleDateFormat("MM/dd");
    SimpleDateFormat out = new SimpleDateFormat("MMMM, dd");

    System.out.println(out.format(in.parse("07/08")));

}