Velocity with the tool class Datetool, Numbertool, etc... __velocity

Source: Internet
Author: User
Tags function examples

Org.apache.velocity.tools.generic.DateTool
Jfinal can add Request.setattribute ("date", new Datetool ()) to the interceptor, which you can use at any time in the velocity template of the. vm.

About date, as follows:

function examples Show results

function Examples

Show Results

$date

2008-04-22

$date. Long

April 22, 2008 10:58 P.M. 54 seconds

$date. Medium_time

22:58:54

$date. full_date

April 22, 2008 Tuesday

$date. yyyy

2008

$date. Get (' Default ', ' short ')

2008-4-22 10:58

$date. Get (' yyyy-m-d h:m:s ')

2008-4-22 22:58:54

$date. Whenis (' 2008-04-20 ')

2 Days hours ago

$date. Whenis (' 2008-04-20 '). Full

2 hours minutes seconds 484 milliseconds ago

$date. Whenis (' 2008-04-20 ').

-2

$date. Whenis (' 2008-04-20 ')

Hours minutes ago

$date. Whenis (' 2008-04-20 ', ' 2008-04-20 ')

Same time

$date. Difference (' 2008-04-20 ', ' 2008-04-20 ')

2 days

$date. Whenis (' 2008-04-20 ').

-2























Org.apache.velocity.tools.generic.MathTool jfinal can be added to the Interceptor Request.setattribute ("math", New Mathtool ()), Date you can use it at any time in the. VM's velocity template.
About math, as follows:
function examples Show results

function Examples

Show Results

$math. Add ("10", "4")

14

$math. Sub ("100", "20")

80

$math. Mul ("11", "7")

77

$math. Div ("100", "5")

20

$math. Idiv ("100", "5")

20

$math. Pow ("2", "5")

32

$math. MoD ("13", "5")

3

$math. Max ("99", "16")

99

$math. Min ("99", "16")

16

$math. ABS ("-99")

99

\ $math. Cell ("99.26")

$math. Cell ("99.26")

$math. Floor ("99.26")

99

$math. Random

0.7663665545444911

$math. Random ("1", "10")

2

$math. Roundto ("2", "5")

5.0

$math. Tointeger ("15")

15

$math. ToDouble ("15")

15.0

$math. Tonumber ("15")

15



























Org.apache.velocity.tools.generic.NumberTool jfinal can add Request.setattribute ("number", new Numbertool ()) to the Interceptor, Date you can use it at any time in the. VM's velocity template.
About number, as follows:
function examples Show results

$number. Locale

Zh_cn

$number. Format ("35")

35.0

$number. Integer ("35.47")

35

$number. Number ("35.47")

35.47

$number. Percent ("0.3547")

35%

$number. Tonumber ("35.47")

35.47

$number. Format ("#0.00", 35.5659)

35.56 Keep two decimal digits




Org.apache.velocity.tools.generic.SortTool
Jfinal can add Request.setattribute ("Sorter", New Sorttool ()) to the interceptor, which you can use at any time in the velocity profile of the. vm.
About Sorter, as follows:
function examples Show results

function Examples

Show Results

$sorter. Sort ([' d ', ' A ', ' B ', ' C '])

[A, B, C, d]

$sorter. Sort ([5,1,12,3])

[1, 3, 5, 12]


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.