Example usage for java.text DateFormat getDateTimeInstance

List of usage examples for java.text DateFormat getDateTimeInstance

Introduction

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

Prototype

public static final DateFormat getDateTimeInstance(int dateStyle, int timeStyle) 

Source Link

Document

Gets the date/time formatter with the given date and time formatting styles for the default java.util.Locale.Category#FORMAT FORMAT locale.

Usage

From source file:CalendarManipulation.java

public static void main(String s[]) {
    Calendar cal = Calendar.getInstance();
    DateFormat df = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.MEDIUM);

    System.out.println(df.format(cal.getTime()));
}

From source file:CalendarManipulation.java

public static void main(String s[]) {
    Calendar cal = Calendar.getInstance();
    DateFormat df = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.MEDIUM);

    System.out.println(df.format(cal.getTime()));

    cal.add(Calendar.DATE, 8);//from www .  j  av a 2  s .c  o m
    System.out.println(df.format(cal.getTime()));
}

From source file:CalendarManipulation.java

public static void main(String s[]) {
    Calendar cal = Calendar.getInstance();
    DateFormat df = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.MEDIUM);

    System.out.println(df.format(cal.getTime()));

    cal.add(Calendar.HOUR, -4);// w ww.  j  a va 2 s  . co m
    System.out.println(df.format(cal.getTime()));
}

From source file:CalendarManipulation.java

public static void main(String s[]) {
    Calendar cal = Calendar.getInstance();
    DateFormat df = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.MEDIUM);

    System.out.println(df.format(cal.getTime()));

    cal.add(Calendar.AM_PM, 1);/*  w  w w  . j  a v  a  2s .  c om*/
    System.out.println(df.format(cal.getTime()));
}

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

From source file:Test.java

public static void main(String[] args) {
    Locale locale = Locale.getDefault();
    Calendar calendar = Calendar.getInstance();
    calendar.setWeekDate(2012, 16, 3);/*from   ww w  . java2s. c o m*/

    System.out.println(
            DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG).format(calendar.getTime()));
    System.out.println("" + locale.getDisplayLanguage());

    Locale.setDefault(Locale.Category.FORMAT, Locale.JAPANESE);
    Locale.setDefault(Locale.Category.DISPLAY, Locale.GERMAN);

    System.out.println(
            DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG).format(calendar.getTime()));
    System.out.println("" + locale.getDisplayLanguage());

}

From source file:Test.java

public static void main(String[] args) {
    Calendar calendar = Calendar.getInstance();
    if (calendar.isWeekDateSupported()) {
        System.out.println("Number of weeks in this year: " + calendar.getWeeksInWeekYear());
        System.out.println("Current week number: " + calendar.get(Calendar.WEEK_OF_YEAR));
    }// ww  w .j  ava2s  .c om

    calendar.setWeekDate(2012, 16, 3);
    System.out.println(
            DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG).format(calendar.getTime()));

}

From source file:Test.java

public static void main(String[] args) {
    Calendar calendar = Calendar.getInstance();
    calendar.setWeekDate(2012, 16, 3);/* w w w  .j  a v a2s. c o  m*/

    Builder builder = new Builder();
    builder.setLanguage("hy");
    builder.setScript("Latn");
    builder.setRegion("IT");
    builder.setVariant("arevela");

    Locale locale = builder.build();
    Locale.setDefault(locale);

    System.out.println(
            DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG).format(calendar.getTime()));
    System.out.println("" + locale.getDisplayLanguage());

    builder.setLanguage("zh");
    builder.setScript("Hans");
    builder.setRegion("CN");

    locale = builder.build();
    Locale.setDefault(locale);

    System.out.println(
            DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG).format(calendar.getTime()));
    System.out.println("" + locale.getDisplayLanguage());

}

From source file:org.northrop.leanne.publisher.Main.java

public static void main(String[] args) {
    CommandLineParser parser = new GnuParser();
    try {//from   w w  w  .  ja  v a 2s.  c o  m
        // parse the command line arguments
        CommandLine line = parser.parse(options, args);

        if (args.length == 0 || line.hasOption("help")) {
            HelpFormatter formatter = new HelpFormatter();
            formatter.printHelp("pub", options);
        } else if (line.hasOption("version")) {
            URLClassLoader cl = (URLClassLoader) Main.class.getClassLoader();
            String title = "";
            String version = "";
            String date = "";
            try {
                URL url = cl.findResource("META-INF/MANIFEST.MF");
                Manifest manifest = new Manifest(url.openStream());
                Attributes attr = manifest.getMainAttributes();
                title = attr.getValue("Implementation-Title");
                version = attr.getValue("Implementation-Version");
                date = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.MEDIUM)
                        .format(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(attr.getValue("Built-Date")));
            } catch (Exception e) {
                e.printStackTrace();
            }

            System.out.println("------------------------------------------------------------");
            System.out.println("Publisher Pipeline " + version);
            System.out.println("------------------------------------------------------------");
            System.out.println("");
            System.out.println(title + " build time " + date);
            System.out.println("Java: " + System.getProperty("java.version"));
            System.out.println("JVM:  " + System.getProperty("java.vendor"));
            System.out.println("OS:   " + System.getProperty("os.name") + " " + System.getProperty("os.version")
                    + " " + System.getProperty("os.arch"));
        } else {
            Option[] options = line.getOptions();
            Binding binding = new Binding();
            binding.setVariable("home", System.getProperty("pub.home"));
            binding.setVariable("inputDir", System.getProperty("pub.home") + "/input");
            binding.setVariable("outputDir", System.getProperty("pub.home") + "/output");
            binding.setVariable("appName", System.getProperty("program.name"));
            binding.setVariable("isdebug", false);

            for (int i = 0; i < options.length; i++) {
                Option opt = options[i];
                binding.setVariable("is" + opt.getOpt(), true);
            }

            String[] roots = new String[] { System.getProperty("pub.home") + "/resources/scripts",
                    System.getProperty("pub.home") + "/resources/scripts/formats" };
            ClassLoader parent = Main.class.getClassLoader();
            GroovyScriptEngine gse = new GroovyScriptEngine(roots, parent);

            if (!line.hasOption("rerun")) {
                gse.run("prep.groovy", binding);
            }

            for (String name : getFormats()) {
                if (line.hasOption(name.toLowerCase())) {
                    String file = ("" + name.charAt(0)).toLowerCase() + name.substring(1) + ".groovy";
                    gse.run(file, binding);
                }
            }
        }
    } catch (ParseException exp) {
        System.err.println("Command line parsing failed.  Reason: " + exp.getMessage());
    } catch (ResourceException resourceError) {
        System.err.println("Groovy script failed.  Reason: " + resourceError.getMessage());
    } catch (IOException ioError) {
        System.err.println("Groovy script failed.  Reason: " + ioError.getMessage());
    } catch (ScriptException error) {
        System.err.println("Groovy script failed.  Reason: " + error.getMessage());
        error.printStackTrace();
    }
}

From source file:org.easyrec.utils.Benchmark.java

public static void main(String[] args) {

    Connection con = null;/* w w  w . j a  v  a 2 s . c  o  m*/
    try {
        Class.forName("com.mysql.jdbc.jdbc2.optional.MysqlDataSource");
        con = DriverManager.getConnection("jdbc:mysql://" + DB_HOST + "/" + DB_NAME, DB_USER, DB_PASSWORD);

        System.out.println("begin:"
                + DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.SHORT).format(new Date()));
        Statement st = con.createStatement();
        initItemAndUserIds();

        st.executeUpdate("DELETE FROM action;");
        st.executeUpdate("DELETE FROM item;");
        st.executeUpdate("DELETE FROM itemassoc;");
        st.executeUpdate("DELETE FROM idmapping;");
        System.out.println("db reset.");

        createItems(st);
        createIdMapping(st);
        createActions(st, NUMBER_OF_ACTIONS);
        startPlugins();

        System.out.println("end:"
                + DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.SHORT).format(new Date()));

    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        if (con != null) {
            try {
                con.close();
            } catch (SQLException ex) {
                logger.warn("An error occured", ex);
            }
        }
    }
}