List of usage examples for java.text DateFormat getDateTimeInstance
public static final DateFormat getDateTimeInstance(int dateStyle, int timeStyle, Locale aLocale)
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 ww . ja v a 2s .com 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: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;/* w w w. j av a2s .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:com.vityuk.ginger.provider.format.JdkDateUtils.java
private static DateFormat createJdkDateFormat(FormatType formatType, DateFormatStyle formatStyle, Locale locale) {// w w w . j a va 2s .co m int style = createJdkDateStyleCode(formatStyle); switch (formatType) { case TIME: return DateFormat.getTimeInstance(style, locale); case DATE: return DateFormat.getDateInstance(style, locale); case DATETIME: return DateFormat.getDateTimeInstance(style, style, locale); } throw new IllegalArgumentException(); }
From source file:DateLocaleServlet.java
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, java.io.IOException { //Get the client's Locale Locale locale = request.getLocale(); ResourceBundle bundle = ResourceBundle.getBundle("i18n.WelcomeBundle", locale); String welcome = bundle.getString("Welcome"); String date = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.SHORT, locale).format(new Date()); //Display the locale response.setContentType("text/html"); java.io.PrintWriter out = response.getWriter(); out.println("<html><head><title>" + welcome + "</title></head><body>"); out.println("<h2>" + bundle.getString("Hello") + " " + bundle.getString("and") + " " + welcome + "</h2>"); out.println(date + "<br /><br />"); java.util.Enumeration e = bundle.getKeys(); while (e.hasMoreElements()) { out.println((String) e.nextElement()); out.println("<br /><br />"); }// w w w . jav a 2 s. co m out.println("Locale: "); out.println(locale.getLanguage() + "_" + locale.getCountry()); out.println("</body></html>"); }
From source file:com.job.portal.HomeController.java
@RequestMapping(value = "/test", method = RequestMethod.GET) public String home(Locale locale, Model model) { System.out.println("Welcome Client krish change " + locale.getCountry()); Date date = new Date(); DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, locale); String formattedDate = dateFormat.format(date); model.addAttribute("serverTime", formattedDate); return "home"; }
From source file:org.jdal.vaadin.data.converter.DateConverter.java
@Override protected DateFormat getFormat(Locale locale) { if (locale == null) locale = LocaleContextHolder.getLocale(); DateFormat f = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT, locale); f.setLenient(false);/*from w ww.jav a 2s . com*/ return f; }
From source file:org.openmrs.util.Format.java
public static String format(Date date, Locale locale, FORMAT_TYPE type) { log.debug("Formatting date: " + date + " with locale " + locale); DateFormat dateFormat = null; if (type == FORMAT_TYPE.TIMESTAMP) { dateFormat = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, locale); } else if (type == FORMAT_TYPE.TIME) { dateFormat = DateFormat.getTimeInstance(DateFormat.MEDIUM, locale); } else {/*w w w.jav a 2s . co m*/ dateFormat = DateFormat.getDateInstance(DateFormat.SHORT, locale); } return date == null ? "" : dateFormat.format(date); }
From source file:com.truthbean.demo.ssm.controller.HomeController.java
/** * Simply selects the home view to render by returning its name. *//*from w ww . ja v a 2s. c o m*/ @RequestMapping(value = "/index.html", method = RequestMethod.GET) public String home(Locale locale, Model model) { logger.info("Welcome home! The client locale is {}.", locale); Date date = new Date(); DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, locale); String formattedDate = dateFormat.format(date); System.out.println(formattedDate); model.addAttribute("serverTime", formattedDate); return "view/home"; }
From source file:lucee.commons.i18n.FormatUtil.java
public static DateFormat[] getDateTimeFormats(Locale locale, TimeZone tz, boolean lenient) { String id = "dt-" + locale.hashCode() + "-" + tz.getID() + "-" + lenient; DateFormat[] df = formats.get(id); if (df == null) { List<DateFormat> list = new ArrayList<DateFormat>(); list.add(DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL, locale)); list.add(DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.LONG, locale)); list.add(DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.MEDIUM, locale)); list.add(DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.SHORT, locale)); list.add(DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.FULL, locale)); list.add(DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, locale)); list.add(DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.MEDIUM, locale)); list.add(DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.SHORT, locale)); list.add(DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.FULL, locale)); list.add(DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.LONG, locale)); list.add(DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM, locale)); list.add(DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.SHORT, locale)); list.add(DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.FULL, locale)); list.add(DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.LONG, locale)); list.add(DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.MEDIUM, locale)); list.add(DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT, locale)); add24(list, locale);/*from w w w .j a va2s. c o m*/ addCustom(list, locale, FORMAT_TYPE_DATE_TIME); df = list.toArray(new DateFormat[list.size()]); for (int i = 0; i < df.length; i++) { df[i].setLenient(lenient); df[i].setTimeZone(tz); } formats.put(id, df); } return df; }