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, Locale aLocale) 

Source Link

Document

Gets the date/time formatter with the given formatting styles for the given locale.

Usage

From source file:ShowDate.java

public static void main(String[] args) {
    DateFormat df = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM, Locale.CANADA_FRENCH);
    System.out.println(df.format(new Date()));
}

From source file:Main.java

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

    String s = dateFormat.format(new Date());
    System.out.println(s);/*from ww w.ja  va 2 s .  com*/

}

From source file:MainClass.java

public static void main(String[] args) {
    Date today = new Date();
    DateFormat fmt = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL, Locale.US);
    String formatted = fmt.format(today);
    System.out.println(formatted);
}

From source file:Main.java

/** Typical main method ("main program") declaration */
public static void main(String[] av) {

    Locale l1 = new Locale("en", "US"), l2 = new Locale("es", "ES");

    // Create a Date object for May 5, 1986
    Calendar c = Calendar.getInstance();
    c.set(1986, 04, 05); // May 5, 1986
    Date d1 = c.getTime();//ww  w  . j  a  va  2  s.  c om

    // Create a Date object for today.
    Date d2 = new Date(); // today

    DateFormat df_us = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM, l1),
            df_sp = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM, l2);
    System.out.println("Date d1 for US is " + df_us.format(d1));
    System.out.println("Date d1 for Spain is " + df_sp.format(d1));
    System.out.println("Date d2 is " + df_us.format(d2));
}

From source file:JapaneseCalendar.java

public static void main(String[] args) {
    Locale japanese = new Locale("ja", "JP", "JP");

    Calendar cal = Calendar.getInstance(japanese);
    DateFormat df = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL, japanese);
    String str = df.format(cal.getTime());

    JOptionPane.showMessageDialog(null, str);
}

From source file:Main.java

public static String stringFromDateTime(Date dateTime) throws ParseException {
    String dateTimeString;//from   ww w  .  j  a v a2s. c  om
    DateFormat dateFormatter;

    dateFormatter = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM, Locale.getDefault());
    dateTimeString = dateFormatter.format(dateTime);

    return dateTimeString;
}

From source file:Test.java

static void displayLocalizedData(Locale l, long number, Date date) {
    NumberFormat nf = NumberFormat.getInstance(l);
    DateFormat df = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, l);
    System.out.printf("Locale: %s\nNumber: %s\nDate: %s\n\n", l.getDisplayName(), nf.format(number),
            df.format(date));//from  ww w .j  a  v  a 2  s  .  c  o  m
}

From source file:Main.java

/**
 * Formats date//from ww w  .ja  v a  2  s .  c o m
 *
 * @param time   Time to format
 * @param locale Locale
 * @return Formatted string
 */
public static String formatDateTime(Date time, Locale locale) {
    DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.SHORT, locale);
    return dateFormat.format(time);
}

From source file:Main.java

public static String getDateCurrentTimeZone() {
    StringBuilder sb = new StringBuilder();
    try {/*  ww  w . jav a  2s . c o  m*/
        Calendar calendar = Calendar.getInstance();
        calendar.setTimeInMillis(System.currentTimeMillis());
        DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.DEFAULT, DateFormat.DEFAULT,
                Locale.getDefault());
        Date currentTimeZone = calendar.getTime();
        sb.append(dateFormat.format(currentTimeZone));
    } catch (Exception e) {
        e.printStackTrace();
    }
    return sb.toString();
}

From source file:MyServlet.java

public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
    res.setContentType("text/plain");
    PrintWriter out = res.getWriter();
    res.setHeader("Content-Language", "es");

    Locale locale = new Locale("es", "");
    DateFormat fmt = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, locale);
    fmt.setTimeZone(TimeZone.getDefault());

    out.println("En Espa\u00f1ol:");
    out.println("\u00a1Hola Mundo!");
    out.println(fmt.format(new Date()));
}