Example usage for java.text DateFormat LONG

List of usage examples for java.text DateFormat LONG

Introduction

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

Prototype

int LONG

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

Click Source Link

Document

Constant for long style pattern.

Usage

From source file:Main.java

private static DateFormat defaultDateFormat() {
    return SimpleDateFormat.getDateInstance(DateFormat.LONG);
}

From source file:Main.java

public static String normalizeDate(String rDate) {
    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-mm-dd", Locale.US);
    Date date = null;/*from   w ww  . j  a v a 2 s .  com*/
    try {
        date = simpleDateFormat.parse(rDate);
    } catch (ParseException e) {
        e.printStackTrace();
    }

    return DateFormat.getDateInstance(DateFormat.LONG).format(date);
}

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 a2 s  .c  om
}

From source file:Main.java

/**
 * Formats date//from   w  ww . j  a v a 2  s .  com
 *
 * @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: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()));
}

From source file:MyServlet.java

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

    Locale locale = new Locale("ja", "");
    DateFormat full = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, locale);
    out.println("In Japanese:");

    try {//from   w  w  w  .j  a va  2s  .  c  om
        FileInputStream fis = new FileInputStream(req.getRealPath("/HelloWorld.ISO-2022-JP"));
        InputStreamReader isr = new InputStreamReader(fis, "ISO-2022-JP");
        BufferedReader reader = new BufferedReader(isr);
        String line = null;
        while ((line = reader.readLine()) != null) {
            out.println(line);
        }
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }

    out.println(full.format(new Date()));
}

From source file:Main.java

public static String DateMessage(Date d, Context c) {
    DateFormat df = DateFormat.getDateTimeInstance();
    DateFormat dfS = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
    DateFormat dfM = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM);
    DateFormat dfL = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG);
    DateFormat dfF = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL);

    DateFormat dfNoTime = DateFormat.getDateInstance();
    DateFormat dfSNoTime = DateFormat.getDateInstance(DateFormat.SHORT, Locale.ENGLISH);
    DateFormat dfMNoTime = DateFormat.getDateInstance(DateFormat.MEDIUM, Locale.ENGLISH);
    DateFormat dfLNoTime = DateFormat.getDateInstance(DateFormat.LONG, Locale.ENGLISH);
    DateFormat dfFNoTime = DateFormat.getDateInstance(DateFormat.FULL, Locale.ENGLISH);
    DateFormat dfDevice = android.text.format.DateFormat.getDateFormat(c);

    String s = dfDevice.format(d) + " or \n" + dfS.format(d) + " or \n" + dfM.format(d) + " or \n"
            + dfL.format(d) + " or \n" + dfF.format(d);

    return s;/*from w w  w .j  a  v a 2  s. co m*/

}

From source file:HelloJapan.java

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

    Locale locale = new Locale("ja", "");
    DateFormat full = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, locale);
    out.println("In Japanese:");
    out.println("\u4eca\u65e5\u306f\u4e16\u754c"); // Hello World
    out.println(full.format(new Date()));
}

From source file:MyServlet.java

public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
    Locale locale;//from  ww  w .j  ava 2  s  .com
    DateFormat full;

    try {
        res.setContentType("text/plain; charset=UTF-8");
        //PrintWriter out = res.getWriter();
        PrintWriter out = new PrintWriter(new OutputStreamWriter(res.getOutputStream(), "UTF8"), true);

        locale = new Locale("en", "US");
        full = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, locale);
        out.println("In English appropriate for the US:");
        out.println("Hello World!");
        out.println(full.format(new Date()));
        out.println();

        locale = new Locale("es", "");
        full = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, locale);
        out.println("En Espa\u00f1ol:");
        out.println("\u00a1Hola Mundo!");
        out.println(full.format(new Date()));
        out.println();

        locale = new Locale("ja", "");
        full = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, locale);
        out.println("In Japanese:");
        out.println("\u4eca\u65e5\u306f\u4e16\u754c");
        out.println(full.format(new Date()));
        out.println();

        locale = new Locale("zh", "");
        full = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, locale);
        out.println("In Chinese:");
        out.println("\u4f60\u597d\u4e16\u754c");
        out.println(full.format(new Date()));
        out.println();

        locale = new Locale("ko", "");
        full = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, locale);
        out.println("In Korean:");
        out.println("\uc548\ub155\ud558\uc138\uc694\uc138\uacc4");
        out.println(full.format(new Date()));
        out.println();

        locale = new Locale("ru", "");
        full = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, locale);
        out.println("In Russian (Cyrillic):");
        out.print("\u0417\u0434\u0440\u0430\u0432\u0441\u0442");
        out.println("\u0432\u0443\u0439, \u041c\u0438\u0440");
        out.println(full.format(new Date()));
        out.println();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:Main.java

public static Date FormatDate(String sRecDate, Context c) {
    DateFormat df = DateFormat.getDateTimeInstance();
    DateFormat dfS = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
    DateFormat dfM = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM);
    DateFormat dfL = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG);
    DateFormat dfF = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL);

    DateFormat dfNoTime = DateFormat.getDateInstance();
    DateFormat dfSNoTime = DateFormat.getDateInstance(DateFormat.SHORT, Locale.ENGLISH);
    DateFormat dfMNoTime = DateFormat.getDateInstance(DateFormat.MEDIUM, Locale.ENGLISH);
    DateFormat dfLNoTime = DateFormat.getDateInstance(DateFormat.LONG, Locale.ENGLISH);
    DateFormat dfFNoTime = DateFormat.getDateInstance(DateFormat.FULL, Locale.ENGLISH);
    DateFormat dfDevice = android.text.format.DateFormat.getDateFormat(c);

    Date dRecDate = null;//from w  w  w  . j  a va2  s .  co  m

    try {
        dRecDate = dfDevice.parse(sRecDate);
    } catch (ParseException e) {
        try {
            dRecDate = df.parse(sRecDate);
        } catch (ParseException e2) {

            try {
                dRecDate = dfS.parse(sRecDate);
            } catch (ParseException e3) {

                try {
                    dRecDate = dfM.parse(sRecDate);
                } catch (ParseException e4) {

                    try {
                        dRecDate = dfL.parse(sRecDate);
                    } catch (ParseException e5) {

                        try {
                            dRecDate = dfF.parse(sRecDate);
                        } catch (ParseException e6) {

                            try {
                                dRecDate = dfNoTime.parse(sRecDate);
                            } catch (ParseException e7) {

                                try {
                                    dRecDate = dfSNoTime.parse(sRecDate);
                                } catch (ParseException e8) {

                                    try {
                                        dRecDate = dfMNoTime.parse(sRecDate);
                                    } catch (ParseException e9) {

                                        try {
                                            dRecDate = dfLNoTime.parse(sRecDate);
                                        } catch (ParseException e10) {

                                            try {
                                                dRecDate = dfFNoTime.parse(sRecDate);
                                            } catch (ParseException e11) {

                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    return dRecDate;

}