-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdates
41 lines (30 loc) · 1.24 KB
/
dates
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import java.text.SimpleDateFormat
import java.util.Calendar
def dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
def calendar = Calendar.getInstance()
// Set the date to the day after tomorrow
calendar.add(Calendar.DAY_OF_YEAR, 2)
// Set the time to 8:00 am
calendar.set(Calendar.HOUR_OF_DAY, 8)
calendar.set(Calendar.MINUTE, 0)
calendar.set(Calendar.SECOND, 0)
// Format the date to the desired string format
def dateString = dateFormat.format(calendar.time)
echo "Date and Time of the day after tomorrow at 8 am: ${dateString}"
def isTimeWithinRange(startTimeStr, endTimeStr) {
// Current time
def currentTime = new Date()
// Parse start and end times
def startTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(startTimeStr)
def endTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(endTimeStr)
// Check if the current time is within the specified range
return (currentTime.after(startTime) && currentTime.before(endTime))
}
// Example usage
def startTimeString = "2023-01-01 08:00:00"
def endTimeString = "2023-01-01 17:00:00"
if (isTimeWithinRange(startTimeString, endTimeString)) {
echo "Current time is within the specified range."
} else {
echo "Current time is outside the specified range."
}