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) throws Exception {
    long yourmilliseconds = 1119193123;
    SimpleDateFormat sdf = new SimpleDateFormat("MMM dd,yyyy HH:mm:ss.SSS");

    Date resultdate = new Date(yourmilliseconds);
    System.out.println(sdf.format(resultdate));
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    // The hour (1-12)
    Format formatter = new SimpleDateFormat("h");
    String s = formatter.format(new Date());
    System.out.println(s);//  w w  w.j ava 2  s. com
}

From source file:Main.java

public static void main(String[] args) {
    String input = "Sun Nov 10 10:00:00 CET 2013";
    SimpleDateFormat parserSDF = new SimpleDateFormat("EEE MMM d HH:mm:ss ZZZ yyyy");
    System.out.println(parserSDF.parse(input, new ParsePosition(0)));
}

From source file:Main.java

public static void main(String[] args) {
    Date date = new Date();
    String strDateFormat = "d";
    SimpleDateFormat sdf = new SimpleDateFormat(strDateFormat);
    System.out.println("Current day in d format : " + sdf.format(date));

}

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[] argv) throws Exception {
    Date date = new Date();
    Format formatter = new SimpleDateFormat("hh:mm:ss a");
    String s = formatter.format(date);
    System.out.println(s);/*from  ww w  .j a v a 2  s. c  o m*/
}

From source file:Main.java

public static void main(String[] argv) {
    java.util.Date date;/* ww  w. j  a  v a2  s  .c om*/
    SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");

    // Lenient
    try {
        date = sdf.parse("40/02/2015");
        System.out.println("Lenient date is :                  " + date);
    } catch (ParseException e) {
        e.printStackTrace();
    }

    // Rigorous
    sdf.setLenient(false);

    try {
        date = sdf.parse("40/02/2015");
        System.out.println("Rigorous date (won't be printed!): " + date);
    } catch (ParseException e) {
        e.printStackTrace();
    }

}

From source file:Main.java

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

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

From source file:Main.java

public static void main(String[] argv) throws Exception {
    Date date = new Date();

    Format formatter = new SimpleDateFormat("MM/dd/yy");
    String s = formatter.format(date);
    System.out.println(s);/*  w  ww . ja  v  a  2 s  .com*/
}

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