Example usage for java.text DateFormat SHORT

List of usage examples for java.text DateFormat SHORT

Introduction

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

Prototype

int SHORT

To view the source code for java.text DateFormat SHORT.

Click Source Link

Document

Constant for short style pattern.

Usage

From source file:DateFormatDemo.java

public static void main(String args[]) {
    Date date = new Date();
    DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT);
    System.out.println("Short form: " + df.format(date));

}

From source file:DateFormatDemo.java

public static void main(String args[]) {
    Date date = new Date();
    DateFormat df = DateFormat.getTimeInstance(DateFormat.SHORT);
    System.out.println("Short form: " + df.format(date));

}

From source file:Main.java

public static void main(String[] args) {
    Date date = new Date();
    String strDate = DateFormat.getDateInstance(DateFormat.SHORT).format(date);

    System.out.println(strDate);/*from   w w  w.jav  a  2s .c  o m*/
}

From source file:Main.java

public static void main(String args[]) {
    SimpleDateFormat df = (SimpleDateFormat) DateFormat.getDateInstance(DateFormat.SHORT);
    System.out.println("The short date format is  " + df.toPattern());
    Locale loc = Locale.ITALY;
    df = (SimpleDateFormat) DateFormat.getDateInstance(DateFormat.SHORT, loc);
    System.out.println("The short date format is  " + df.toPattern());
}

From source file:MainClass.java

public static void main(String[] args) {
    DateFormat shortDf = DateFormat.getDateInstance(DateFormat.SHORT);

    DateFormat mediumDf = DateFormat.getDateInstance(DateFormat.MEDIUM);
    DateFormat longDf = DateFormat.getDateInstance(DateFormat.LONG);
    DateFormat fullDf = DateFormat.getDateInstance(DateFormat.FULL);
    System.out.println(shortDf.format(new Date()));
    System.out.println(mediumDf.format(new Date()));
    System.out.println(longDf.format(new Date()));
    System.out.println(fullDf.format(new Date()));

    // parsing//w  ww  .j  a  v a2 s .  c om
    try {
        Date date = shortDf.parse("Jan 32, 2005");
    } catch (ParseException e) {
    }
}

From source file:MainClass.java

public static void main(String[] args) {
    DateFormat shortDf = DateFormat.getDateInstance(DateFormat.SHORT);

    DateFormat mediumDf = DateFormat.getDateInstance(DateFormat.MEDIUM);
    DateFormat longDf = DateFormat.getDateInstance(DateFormat.LONG);
    DateFormat fullDf = DateFormat.getDateInstance(DateFormat.FULL);
    System.out.println(shortDf.format(new Date()));
    System.out.println(mediumDf.format(new Date()));
    System.out.println(longDf.format(new Date()));
    System.out.println(fullDf.format(new Date()));

    // parsing//from  w  w w  .ja  va 2  s.co m
    try {
        Date date = shortDf.parse("12/12/2006");
    } catch (ParseException e) {
    }
}

From source file:DateTest.java

public static void main(String[] args) throws ParseException {
    DateFormat formatter = DateFormat.getDateInstance(DateFormat.SHORT);
    formatter.setLenient(false);//from  ww w .ja v  a  2  s .c o  m
    Date theDate = formatter.parse(args[0]);
    System.out.println(theDate);
}

From source file:Main.java

public static void main(String[] argv) {

    JFormattedTextField tft2 = new JFormattedTextField(DateFormat.getDateInstance(DateFormat.SHORT));
    tft2.setValue(new Date());

}

From source file:TimeFormatDemo.java

public static void main(String args[]) {
    Date date = new Date();
    DateFormat df;/*  w ww .ja  va2  s  .com*/

    df = DateFormat.getTimeInstance(DateFormat.SHORT, Locale.JAPAN);
    System.out.println("Japan: " + df.format(date));

    df = DateFormat.getTimeInstance(DateFormat.LONG, Locale.UK);
    System.out.println("United Kingdom: " + df.format(date));

    df = DateFormat.getTimeInstance(DateFormat.FULL, Locale.CANADA);
    System.out.println("Canada: " + df.format(date));
}

From source file:Main.java

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

    // Format date in a short format
    String today = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT).format(date);
    System.out.println("Today " + today);

    // Format date in a medium format
    today = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM).format(date);
    System.out.println("Today " + today);

    // Format date in a long format
    today = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG).format(date);
    System.out.println("Today " + today);
}