Date 将日期与Velocity脚本进行比较?
我目前正在使用Marketo,我们希望通过查看输入自定义对象信息的日期来查看一些数据 我知道php、javascript等,但Velocity是一个新事物,尽管我很熟悉,但我无法找出比较日期的最佳方法 在下面的代码中,我尝试了两种方法,使用数字工具或日期工具,但运气不太好。 ##获取所有自定义对象数据 #集合($items=${customerPurchaseData_cList})Date 将日期与Velocity脚本进行比较?,date,datetime,velocity,marketo,Date,Datetime,Velocity,Marketo,我目前正在使用Marketo,我们希望通过查看输入自定义对象信息的日期来查看一些数据 我知道php、javascript等,但Velocity是一个新事物,尽管我很熟悉,但我无法找出比较日期的最佳方法 在下面的代码中,我尝试了两种方法,使用数字工具或日期工具,但运气不太好。 ##获取所有自定义对象数据 #集合($items=${customerPurchaseData_cList}) #set($currentDateNumber=$number.tonNumber('25/01/2016'))
#set($currentDateNumber=$number.tonNumber('25/01/2016'))
#set($startDateNumber=$number.tonNumber($item.orderDate))
$currentDateNumber
$startDateNumber
#如果($startDateNumber 0)
$item.MetalType
#结束##结束if语句
#结束,结束
##>$date.get('2017-01-01')
###如果($item.orderDate>$date.get('2017-01-01'))
有没有比较日期值的简单方法?比如把它们转换成UNIX时间戳
你的帮助太棒了 查看Velocity Apache API中的
类ComparisonDataTool
:
只要日期格式正确,您就应该能够比较这两个日期,并获得对其运行if语句所需的值。此处,#是Velocity模板语法的一部分,因此我们必须使用它
#set ($otherDate = $vtool.formatDate("2020-04-10 00:00:00", "MM/dd/yyyy"))
#set ($currentDate = $vtool.getDate("MM/dd/yyyy"))
#if($currentDate.compareTo($otherDate)<= 0)
//Execute some code.
#end
#set($otherDate=$vtool.formatDate(“2020-04-10 00:00:00”,“MM/dd/yyyy”))
#set($currentDate=$vtool.getDate(“MM/dd/yyyy”))
#如果($currentDate.compareTo($otherDate))是的,我最后使用了compareTo(),在我能够确保这两个日期的格式相同之后,它就工作了。
#set ($otherDate = $vtool.formatDate("2020-04-10 00:00:00", "MM/dd/yyyy"))
#set ($currentDate = $vtool.getDate("MM/dd/yyyy"))
#if($currentDate.compareTo($otherDate)<= 0)
//Execute some code.
#end