有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java FreeMarker从毫秒中删除逗号

使用FreeMarker,我想以毫秒为单位显示日期:

${mydate?long}

但我得到的输出是逗号分隔的毫秒:

524,354,400,000

Freemarker中是否有任何内置函数来删除逗号

谢谢


共 (4) 个答案

  1. # 2 楼答案

    从接受答案的评论中抄袭

    In my version (2.3.26), simply ${myDate?c} will suffice, assuming that myDate is already a long/int.

    这对我有用

    谢谢!

  2. # 3 楼答案

    除了Gil的回答之外,如果在代码中构建配置,可以通过以下方式全局设置标志:

    Configuration cfg = new Configuration();
    ...
    cfg.setNumberFormat("computer");
    
  3. # 4 楼答案

    作为替代方案,您可以在Freemarker模板上写下以下指令:

    <#setting number_format="computer">
    

    这将删除数字中的所有逗号

    这对Freemarker 2.3.23很有效

    有关这些指令的更多信息,请访问:

    http://freemarker.org/docs/ref_directive_setting.html