DateUtil Embedded Objects¶
A DateUtil embedded object provides methods of formatting time and calculating time.
Methods¶
Method | Description | Example |
---|---|---|
String format(Date date, String pattern) | Formats Date to character strings according to the specified pattern. | Convert the planned job scheduling time to the millisecond format. #{DateUtil.format(Job.planTime,"yyyy-MM-dd HH:mm:ss:SSS")} Subtracts one day from the planned job scheduling time and convert the time to the week format.
|
Date addMonths(Date date, int amount) | After the specified number of months is added to Date, the new Date object is returned. The amount can be a negative number. | Subtract one month from the planned job scheduling time and convert the time to the month format. #{DateUtil.format(DateUtil.addMonths(Job.planTime,-1),"yyyy-MM")} |
Date addDays(Date date, int amount) | After the specified number of days is added to Date, the new Date object is returned. The amount can be a negative number. | Subtracts one day from the planned job scheduling time and convert the time to the yyyy-MM-dd format. #{DateUtil.format(DateUtil.addDays(Job.planTime,-1),"yyyy-MM-dd")} Subtracts one day from the planned job scheduling time and convert the time to the week format.
|
Date addHours(Date date, int amount) | After the specified number of hours is added to Date, the new Date object is returned. The amount can be a negative number. | Subtract one hour from the planned job scheduling time and convert the time to the hour format. #{DateUtil.format(DateUtil.addHours(Job.planTime,-1),"yyyy-MM-dd HH")} |
Date addMinutes(Date date, int amount) | After the specified number of minutes is added to Date, the new Date object is returned. The amount can be a negative number. | Subtract one minute from the planned job scheduling time and convert the time to the minute format. #{DateUtil.format(DateUtil.addMinutes(Job.planTime,-1),"yyyy-MM-dd HH:mm")} |
int getDay(Date date) | Obtains the day from the date. For example, if the date is 2018-09-14, 14 is returned. | Obtain the day from the job scheduling plan. #{DateUtil.getDay(Job.planTime)} |
int getMonth(Date date) | Obtains the month from the date. For example, if the date is 2018-09-14, 9 is returned. | Obtain the month from the date. #{DateUtil.getMonth(Job.planTime)} |
int getQuarter(Date date) | Obtains the quarter from the date. For example, if the date is 2018-09-14, 3 is returned. | Obtain the quarter from the date. #{DateUtil.getQuarter(Job.planTime)} |
int getYear(Date date) | Obtains the year from the date. For example, if the date is 2018-09-14, 2018 is returned. | Obtain the year from the date. #{DateUtil.getYear(Job.planTime)} |
Date now() | Returns the current time. | Return the current time accurate to second. #{DateUtil.format(DateUtil.now(),"yyyy-MM-dd HH:mm:ss")} |
long getTime(Date date) | Converts a time of the date type to one of the long type. | Convert the planned job scheduling time to a timestamp. #{DateUtil.getTime(Job.planTime)} |
Date parseDate(String str, String pattern) | Converts the character string to the date by pattern. The pattern is the date and time mode. For details, see Date and Time Mode. | Convert the job start time string to a time accurate to second. #{DateUtil.parseDate(Job.getPlanTime("yyyy-MM-dd HH:mm:ss:SSS"),"yyyy-MM-dd HH:mm:ss")} |
Example¶
The previous day of the job scheduling plan time is used as the subdirectory name to generate an OBS path. The EL expression is as follows:
#{"obs://test/"+DateUtil.format(DateUtil.addDays(Job.planTime,-1),"yyyy-MM-dd")}