Freemarker timestamp to date

Source: Internet
Author: User
Tags timestamp to date

Requirement: Get a variable lastclock from a third party, with a forward value of 1305575275540 and a timestamp. Use freemarker to convert the variable to a common date format on the page.

Import Java. io. stringwriter; import Java. util. hashmap; import Java. util. map; import freemarker. cache. stringtemplateloader; import freemarker. template. configuration; import freemarker. template. template; public final class freemarkutils {Private Static configuration CFG = new configuration (); Private Static string key = "key "; /*** return the rendered value of freemark Based on the template * @ Param name * @ Param map * @ return freemark rendered value * @ thro WS exception * @ author chenqing */public static string gettemplatevalue (string name, Map <string, Object> map) throws exception {stringtemplateloader = new stringtemplateloader (); stringtemplateloader. puttemplate (Key, name); cfg. settemplateloader (stringtemplateloader); Template T = cfg. gettemplate (key); stringwriter out = new stringwriter (); T. process (MAP, out); Return out. tostring () ;}/*** Directly return the rendered value of freemark * @ Param name * @ return freemark the rendered value * @ throws exception */public static string gettemplatevalue (string name) throws exception {return gettemplatevalue (name, new hashmap <string, Object> ();}/*** @ Param ARGs */public static void main (string [] ARGs) {try {Map <string, Object> root = new hashmap <string, Object> (); root. put ("lastclock", "1305575275540"); string out = freemarku Tils. gettemplatevalue ("$ {lastclock? Number? Number_to_datetime} ", root); system. Out. println (out);} catch (exception e) {e. printstacktrace ();}}}



The preceding method can be extended and used for packaging string output, not limited to web pages.

Freemarker timestamp to date

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.