Java Code Examples for freemarker.template.Configuration#setDateFormat()
The following examples show how to use
freemarker.template.Configuration#setDateFormat() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FreemarkerEmailTemplate.java From LuckyFrameClient with GNU Affero General Public License v3.0 | 6 votes |
/** * ģ���������� */ public String getText(String templateId, Map<Object, Object> parameters) { @SuppressWarnings("deprecation") Configuration configuration = new Configuration(); configuration.setTemplateLoader(new ClassTemplateLoader(FreemarkerEmailTemplate.class, TEMPLATE_PATH)); configuration.setDefaultEncoding("gbk"); //configuration.setEncoding(Locale.getDefault(), "UTF-8"); configuration.setDateFormat("yyyy-MM-dd HH:mm:ss"); String templateFile = templateId + SUFFIX; try { Template template = TEMPLATE_CACHE.get(templateFile); if (template == null) { template = configuration.getTemplate(templateFile); TEMPLATE_CACHE.put(templateFile, template); } StringWriter stringWriter = new StringWriter(); parameters.put("webip", WEB_IP); parameters.put("webport", WEB_PORT); template.process(parameters, stringWriter); return stringWriter.toString(); } catch (Exception e) { LogUtil.APP.error("��ȡ�ʼ�ģ���������ó����쳣",e); throw new RuntimeException(e); } }
Example 2
Source File: OutMsgXmlBuilder.java From jfinal-weixin with Apache License 2.0 | 5 votes |
private static Configuration initFreeMarkerConfiguration() { Configuration config = new Configuration(); StringTemplateLoader stringTemplateLoader = new StringTemplateLoader(); initStringTemplateLoader(stringTemplateLoader); config.setTemplateLoader(stringTemplateLoader); // 模板缓存更新时间,对于OutMsg xml 在类文件中的模板来说已有热加载保障了更新 config.setTemplateUpdateDelay(999999); // - Set an error handler that prints errors so they are readable with // a HTML browser. // config.setTemplateExceptionHandler(TemplateExceptionHandler.HTML_DEBUG_HANDLER); config.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER); // - Use beans wrapper (recommmended for most applications) config.setObjectWrapper(ObjectWrapper.BEANS_WRAPPER); // - Set the default charset of the template files config.setDefaultEncoding(encoding); // config.setDefaultEncoding("ISO-8859-1"); // - Set the charset of the output. This is actually just a hint, that // templates may require for URL encoding and for generating META element // that uses http-equiv="Content-type". config.setOutputEncoding(encoding); // config.setOutputEncoding("UTF-8"); // - Set the default locale config.setLocale(Locale.getDefault() /* Locale.CHINA */ ); // config.setLocale(Locale.US); config.setLocalizedLookup(false); // 去掉int型输出时的逗号, 例如: 123,456 // config.setNumberFormat("#"); // config.setNumberFormat("0"); 也可以 config.setNumberFormat("#0.#####"); config.setDateFormat("yyyy-MM-dd"); config.setTimeFormat("HH:mm:ss"); config.setDateTimeFormat("yyyy-MM-dd HH:mm:ss"); return config; }