21

Using FreeMarker, I want to display a date into milliseconds:

${mydate?long}

but I get as output a comma separated millisecond:

524,354,400,000

is there any built-in function in Freemarker to remove comma ?

Thanks

4 Answers 4

27

It looks like as of version 2.3.17 you can use:

${myDate?long?c}

http://sourceforge.net/p/freemarker/feature-requests/72/

4
  • Works ! Yes I'm using 2.3.20. Thanks!
    – Begoodpy
    Feb 5, 2014 at 15:58
  • 1
    In my version (2.3.26), simply ${myDate?c} will suffice, assuming that myDate is already a long/int. Oct 1, 2019 at 21:57
  • 1
    This also works for me, thanks! If anyone else was wondering what the 'c' stands for: It means 'Computer language', so the comma's for human readability are removed: freemarker.apache.org/docs/…
    – Paul S
    Nov 28, 2019 at 14:30
  • @lance.dolan thank you, worked for me, I added this comment as an answer.
    – Jamsheer
    Jun 9, 2021 at 10:16
21

As an alternative you could write on your Freemarker template this directive:

<#setting number_format="computer">

This will remove all commas from numbers.

This works fine for Freemarker 2.3.23

More info about these directives can be found here:

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

0
5

Adding to Gil's answer, if you build the configuration inside your code, you can set the flag globally by :

Configuration cfg = new Configuration();
...
cfg.setNumberFormat("computer");
1

Copied from the comment of the accepted answer,

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

This is worked for me

Thank you

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.