Example usage for java.text DateFormat getDateInstance

List of usage examples for java.text DateFormat getDateInstance

Introduction

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

Prototype

public static final DateFormat getDateInstance(int style, Locale aLocale) 

Source Link

Document

Gets the date formatter with the given formatting style for the given locale.

Usage

From source file:Main.java

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

    Date date = DateFormat.getDateInstance(DateFormat.MEDIUM, Locale.CANADA).parse("29 janv. 2002");
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.LONG, Locale.getDefault());

    String s = dateFormat.format(new Date());
    System.out.println(s);//from  www  . j a  v a2s. co  m

}

From source file:MainClass.java

public static void main(String[] a) {
    Date aDate;/*from  ww w .  j  ava2 s. c o m*/
    DateFormat fmt = DateFormat.getDateInstance(DateFormat.FULL, Locale.US);
    try {
        aDate = fmt.parse("Saturday, July 4, 1998 ");
        System.out.println("The Date string is: " + fmt.format(aDate));
    } catch (java.text.ParseException e) {
        System.out.println(e);
    }
}

From source file:Main.java

public static void main(String args[]) {
    int style = DateFormat.MEDIUM;
    // Also try with style = DateFormat.FULL and DateFormat.SHORT
    Date date = new Date();
    DateFormat df;/*from   ww w.j  a v  a 2s. com*/
    df = DateFormat.getDateInstance(style, Locale.UK);
    System.out.println("United Kingdom: " + df.format(date));
    df = DateFormat.getDateInstance(style, Locale.US);
    System.out.println("USA: " + df.format(date));
    df = DateFormat.getDateInstance(style, Locale.FRANCE);
    System.out.println("France: " + df.format(date));
    df = DateFormat.getDateInstance(style, Locale.ITALY);
    System.out.println("Italy: " + df.format(date));
    df = DateFormat.getDateInstance(style, Locale.JAPAN);
    System.out.println("Japan: " + df.format(date));
}

From source file:MainClass.java

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

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

    df = DateFormat.getDateInstance(DateFormat.MEDIUM, Locale.KOREA);
    System.out.println("Korea: " + df.format(date));

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

    df = DateFormat.getDateInstance(DateFormat.FULL, Locale.US);
    System.out.println("United States: " + df.format(date));
}

From source file:JFormattedTextFieldDateInputSampleDateFormatFULLLocaleUS.java

public static void main(String args[]) {
    JFrame frame = new JFrame("Date/Time Input");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JLabel label;/* w  ww.j  a  va2s .co m*/
    JFormattedTextField input;
    JPanel panel;

    BoxLayout layout = new BoxLayout(frame.getContentPane(), BoxLayout.Y_AXIS);
    frame.setLayout(layout);

    Format fullUSDate = DateFormat.getDateInstance(DateFormat.FULL, Locale.US);
    label = new JLabel("Full US date:");
    input = new JFormattedTextField(fullUSDate);
    input.setValue(new Date());
    input.setColumns(20);

    panel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
    panel.add(label);
    panel.add(input);

    frame.add(panel);
    frame.add(new JTextField());
    frame.pack();
    frame.setVisible(true);
}

From source file:MainClass.java

public static void main(String[] args) {
    Date today = new Date();
    Locale[] locales = { US, UK, GERMANY, FRANCE };
    int[] styles = { FULL, LONG, MEDIUM, SHORT };
    String[] styleNames = { "FULL", "LONG", "MEDIUM", "SHORT" };
    DateFormat fmt = null;//from  w w  w  . j  av  a2s . c  o m
    for (Locale locale : locales) {
        System.out.println("\nThe Date for " + locale.getDisplayCountry() + ":");
        for (int i = 0; i < styles.length; i++) {
            fmt = DateFormat.getDateInstance(styles[i], locale);
            System.out.println("\tIn " + styleNames[i] + " is " + fmt.format(today));
        }
    }
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    String host = "host";
    int port = 25;
    String from = "from@from.net";
    String toAddr = "to@to.net";

    Socket servSocket = new Socket(host, port);
    DataOutputStream os = new DataOutputStream(servSocket.getOutputStream());
    DataInputStream is = new DataInputStream(servSocket.getInputStream());

    if (servSocket != null && os != null && is != null) {
        os.writeBytes("HELO\r\n");
        os.writeBytes("MAIL From:" + from + " \r\n");
        os.writeBytes("RCPT To:" + toAddr + "\r\n");
        os.writeBytes("DATA\r\n");
        os.writeBytes("X-Mailer: Java\r\n");
        os.writeBytes(/*from  w  w  w .  ja  v a  2 s.  c  o m*/
                "DATE: " + DateFormat.getDateInstance(DateFormat.FULL, Locale.US).format(new Date()) + "\r\n");
        os.writeBytes("From:" + from + "\r\n");
        os.writeBytes("To:" + toAddr + "\r\n");
    }

    os.writeBytes("Subject:\r\n");
    os.writeBytes("body\r\n");
    os.writeBytes("\r\n.\r\n");
    os.writeBytes("QUIT\r\n");
    String responseline;
    while ((responseline = is.readUTF()) != null) {
        if (responseline.indexOf("Ok") != -1)
            break;
    }
}

From source file:MainClass.java

public static void main(String[] args) {
    Date today = new Date();
    Locale[] locales = { Locale.US, Locale.UK, Locale.GERMANY, Locale.FRANCE };

    int[] styles = { DateFormat.FULL, DateFormat.LONG, DateFormat.MEDIUM, DateFormat.SHORT };

    DateFormat fmt;//  www.  ja v a2 s  .  c o m
    String[] styleText = { "FULL", "LONG", "MEDIUM", "SHORT" };

    // Output the date for each local in four styles
    for (int i = 0; i < locales.length; i++) {
        System.out.println("\nThe Date for " + locales[i].getDisplayCountry() + ":");
        for (int j = 0; j < styles.length; j++) {
            fmt = DateFormat.getDateInstance(styles[j], locales[i]);
            System.out.println("\tIn " + styleText[j] + " is " + fmt.format(today));
        }
    }
}

From source file:com.hp.mqm.atrf.Main.java

public static void main(String[] args) {

    long start = System.currentTimeMillis();
    setUncaughtExceptionHandler();/*  w  w  w.  ja va  2  s .  c om*/

    CliParser cliParser = new CliParser();
    cliParser.handleHelpAndVersionOptions(args);

    configureLog4J();
    logger.info(System.lineSeparator() + System.lineSeparator());
    logger.info("************************************************************************************");
    DateFormat dateFormatter = DateFormat.getDateInstance(DateFormat.DEFAULT, Locale.getDefault());
    DateFormat timeFormatter = DateFormat.getTimeInstance(DateFormat.DEFAULT, Locale.getDefault());
    logger.info((String.format("Starting HPE ALM Test Result Collection Tool %s %s",
            dateFormatter.format(new Date()), timeFormatter.format(new Date()))));
    logger.info("************************************************************************************");

    FetchConfiguration configuration = cliParser.parse(args);
    ConfigurationUtilities.setConfiguration(configuration);

    App app = new App(configuration);
    app.start();

    long end = System.currentTimeMillis();
    logger.info(String.format("Finished creating tests and test results on ALM Octane in %s seconds",
            (end - start) / 1000));
    logger.info(System.lineSeparator());
}