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) {
    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) {
    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 Exception {
    String someDate = "22/03/2015";
    SimpleDateFormat strToDate = new SimpleDateFormat("dd/MM/yyyy");
    Date currentDate = strToDate.parse(someDate);
    System.out.println("Date is :  " + currentDate);

    String dateFormat = "yyyy-MM-dd HH:mm:ss.SSS";
    SimpleDateFormat dateToStr = new SimpleDateFormat(dateFormat);
    String formattedDate = dateToStr.format(currentDate);
    System.out.println("Formated Date is : " + formattedDate);

}

From source file:Main.java

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

    SimpleDateFormat sdf = new SimpleDateFormat("s");
    System.out.println("seconds in s format : " + sdf.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) {
    Date date = new Date();

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

From source file:Main.java

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

    SimpleDateFormat sdf = new SimpleDateFormat("m");
    System.out.println("minutes in m format : " + sdf.format(date));

}

From source file:Main.java

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

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

From source file:Main.java

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

    SimpleDateFormat sdf = new SimpleDateFormat("zzz");
    System.out.println("TimeZone in z format : " + sdf.format(date));
}