[SoapUI] 各种日期计算

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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
import java.util.*;
import java.text.SimpleDateFormat;
 
// current date
String dateNew = today()
 
// tomorrow
String tomorrow = tomorrow()
 
//  yesterday
String yesterday = yesterday()
 
// the day before yesterday
String theDayBeforeYesterday = theDayBeforeYesterday()
 
// Last Market Close
String lastMarketClose = lastMarketClose()
log.info "------> lastMarketClose : "+lastMarketClose
 
// Last Market Close -2 days
String lastMarketCloseMinus2Days = lastMarketCloseMinus2Days()
 
// Two years ago of Last Market Close -2 days
String twoYearsAgoOfLastMarketCloseMinus2Days = twoYearsAgoOfLastMarketCloseMinus2Days(lastMarketCloseMinus2Days)
 
// yesterday of Last Market Close
String yesterdayOfLastMarketClose = yesterdayOfLastMarketClose(lastMarketClose)
 
// a month ago of Last Market Close
String aMonthAgoOfLastMarketClose = aMonthAgoOfLastMarketClose(lastMarketClose)
 
// three months ago of Last Market Close
String threeMonthsAgoOfLastMarketClose = threeMonthsAgoOfLastMarketClose(lastMarketClose)
 
// three years ago of Last Market Close
String threeYearsAgoOfLastMarketClose = threeYearsAgoOfLastMarketClose(lastMarketClose)
log.info "------> threeYearsAgoOfLastMarketClose : "+threeYearsAgoOfLastMarketClose
 
// the last day of last week
String theLastDayOfLastWeek = theLastDayOfLastWeek()
 
// the last day of  last month
String theLastDayOfLastMonth = theLastDayOfLastMonth()
 
// Get the same day of last month
String theSameDayOfLastMonth = theSameDayOfLastMonth()
 
// The first day of the quarter
String theFirstDayOfTheQuarter = theFirstDayOfTheQuarter()
 
// The last day of last quarter
String theLastDayOfLastQuarter = theLastDayOfLastQuarter(theFirstDayOfTheQuarter)
 
//  a year ago after The last day of last quarter
String aYearAgoAfterTheLastDayOfLastQuarter = aYearAgoAfterTheLastDayOfLastQuarter(theFirstDayOfTheQuarter)
 
// The first day of last quarter
String theFirstDayOfLastQuarter = theFirstDayOfLastQuarter(theFirstDayOfTheQuarter)
 
// The last day of two quarters ago
String theLastDayOfTwoQuartersAgo = theLastDayOfTwoQuartersAgo(theLastDayOfLastQuarter)
 
// The first day of six months ago after two quarters
String theFirstDayOfSixMonthsAgoAfterTwoQuarters = theFirstDayOfSixMonthsAgoAfterTwoQuarters(theLastDayOfTwoQuartersAgo)
 
// yesterday of  three months ago
String yesterdayOfThreeMonthsAgo = yesterdayOfThreeMonthsAgo()
 
// The first day of  two months ago
String theFirstDayOfTwoMonthsAgo = theFirstDayOfTwoMonthsAgo()
 
// The last day of  two months ago
String theLastDayOfTwoMonthsAgo = theLastDayOfTwoMonthsAgo()
 
// The first day of  three months ago
String theFirstDayOfThreeMonthsAgo = theFirstDayOfThreeMonthsAgo()
 
// The first day of  six months ago
String theFirstDayOfSixMonthsAgo = theFirstDayOfSixMonthsAgo()
 
// The first day of this year
String theFirstDayOfThisYear = theFirstDayOfThisYear()
 
// The last day of last year
String theLastDayOfLastYear = theLastDayOfLastYear()
 
// tomorrow of  last year
String tomorrowOfLastYear = tomorrowOfLastYear()
 
// the first day of this month last year
String theFirstDayOfThisMonthLastYear = theFirstDayOfThisMonthLastYear()
 
// the first day of last year
String theFirstDayOfLastYear = theFirstDayOfLastYear()
 
// the same day of this month three years ago
String theSameDayOfThisMonthThreeYearsAgo = theSameDayOfThisMonthThreeYearsAgo()
 
// the first day of this month three years ago
String theFirstDayOfThisMonthThreeYearsAgo = theFirstDayOfThisMonthThreeYearsAgo()
 
// the first day of three years ago
String theFirstDayOfThreeYearsAgo = theFirstDayOfThreeYearsAgo()
 
// Set the project level property : currentDate,yesterDay,lastMonth , its value will updated with dateNew
testRunner.testCase.testSuite.project.setPropertyValue( "currentDate", dateNew )
testRunner.testCase.testSuite.project.setPropertyValue( "tomorrow", tomorrow )
testRunner.testCase.testSuite.project.setPropertyValue( "yesterday", yesterday )
testRunner.testCase.testSuite.project.setPropertyValue( "theDayBeforeYesterday", theDayBeforeYesterday )
testRunner.testCase.testSuite.project.setPropertyValue( "lastMarketClose", lastMarketClose )
testRunner.testCase.testSuite.project.setPropertyValue( "lastMarketCloseMinus2Days", lastMarketCloseMinus2Days )
testRunner.testCase.testSuite.project.setPropertyValue( "twoYearsAgoOfLastMarketCloseMinus2Days", twoYearsAgoOfLastMarketCloseMinus2Days )
testRunner.testCase.testSuite.project.setPropertyValue( "threeYearsAgoOfLastMarketClose", threeYearsAgoOfLastMarketClose )
testRunner.testCase.testSuite.project.setPropertyValue( "theDayBeforeYesterday", theDayBeforeYesterday )
testRunner.testCase.testSuite.project.setPropertyValue( "theLastDayOfLastWeek", theLastDayOfLastWeek )
testRunner.testCase.testSuite.project.setPropertyValue( "yesterdayOfLastMarketClose", yesterdayOfLastMarketClose )
testRunner.testCase.testSuite.project.setPropertyValue( "aMonthAgoOfLastMarketClose", aMonthAgoOfLastMarketClose )
testRunner.testCase.testSuite.project.setPropertyValue( "threeMonthsAgoOfLastMarketClose", threeMonthsAgoOfLastMarketClose )
testRunner.testCase.testSuite.project.setPropertyValue( "theFirstDayOfTheQuarter", theFirstDayOfTheQuarter )
testRunner.testCase.testSuite.project.setPropertyValue( "theLastDayOfLastQuarter", theLastDayOfLastQuarter )
testRunner.testCase.testSuite.project.setPropertyValue( "aYearAgoAfterTheLastDayOfLastQuarter", aYearAgoAfterTheLastDayOfLastQuarter )
testRunner.testCase.testSuite.project.setPropertyValue( "theFirstDayOfLastQuarter", theFirstDayOfLastQuarter )
testRunner.testCase.testSuite.project.setPropertyValue( "theLastDayOfTwoQuartersAgo", theLastDayOfTwoQuartersAgo )
testRunner.testCase.testSuite.project.setPropertyValue( "theFirstDayOfSixMonthsAgoAfterTwoQuarters", theFirstDayOfSixMonthsAgoAfterTwoQuarters )
testRunner.testCase.testSuite.project.setPropertyValue( "theSameDayOfLastMonth", theSameDayOfLastMonth )
testRunner.testCase.testSuite.project.setPropertyValue( "theLastDayOfLastMonth", theLastDayOfLastMonth )
testRunner.testCase.testSuite.project.setPropertyValue( "yesterdayOfThreeMonthsAgo", yesterdayOfThreeMonthsAgo )
testRunner.testCase.testSuite.project.setPropertyValue( "theFirstDayOfTwoMonthsAgo", theFirstDayOfTwoMonthsAgo )
testRunner.testCase.testSuite.project.setPropertyValue( "theLastDayOfTwoMonthsAgo", theLastDayOfTwoMonthsAgo )
testRunner.testCase.testSuite.project.setPropertyValue( "theFirstDayOfThreeMonthsAgo", theFirstDayOfThreeMonthsAgo )
testRunner.testCase.testSuite.project.setPropertyValue( "theFirstDayOfSixMonthsAgo", theFirstDayOfSixMonthsAgo )
testRunner.testCase.testSuite.project.setPropertyValue( "theFirstDayOfThisYear", theFirstDayOfThisYear )
testRunner.testCase.testSuite.project.setPropertyValue( "theLastDayOfLastYear", theLastDayOfLastYear )
testRunner.testCase.testSuite.project.setPropertyValue( "tomorrowOfLastYear", tomorrowOfLastYear )
testRunner.testCase.testSuite.project.setPropertyValue( "theFirstDayOfThisMonthLastYear", theFirstDayOfThisMonthLastYear )
testRunner.testCase.testSuite.project.setPropertyValue( "theFirstDayOfLastYear", theFirstDayOfLastYear )
testRunner.testCase.testSuite.project.setPropertyValue( "theSameDayOfThisMonthThreeYearsAgo", theSameDayOfThisMonthThreeYearsAgo )
testRunner.testCase.testSuite.project.setPropertyValue( "theFirstDayOfThisMonthThreeYearsAgo", theFirstDayOfThisMonthThreeYearsAgo )
testRunner.testCase.testSuite.project.setPropertyValue( "theFirstDayOfThreeYearsAgo", theFirstDayOfThreeYearsAgo )
 
//**********************************************************************Methods**************************************************************************
 
def today(){
    String str = "";
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    Calendar lastDate = Calendar.getInstance();
    str = sdf.format(lastDate.getTime());
    return str;
}
 
def yesterday(){
    String str = "";
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    Calendar lastDate = Calendar.getInstance();
    lastDate.add(Calendar.DATE, -1);
    str = sdf.format(lastDate.getTime());
    return str;
}
 
def theDayBeforeYesterday(){
    String str = "";
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    Calendar lastDate = Calendar.getInstance();
    lastDate.add(Calendar.DATE, -2);
    str = sdf.format(lastDate.getTime());
    return str;
}
 
def theLastDayOfLastMonth(){
    String str = "";
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    Calendar lastDate = Calendar.getInstance();
    lastDate.add(Calendar.MONTH, -1);
    lastDate.set(Calendar.DATE, 1);
    lastDate.roll(Calendar.DATE, -1);
    str = sdf.format(lastDate.getTime());
    return str;
}
 
def theSameDayOfLastMonth(){
    String str = "";
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    Calendar lastDate = Calendar.getInstance();
    lastDate.roll(Calendar.MONTH, -1);
    str = sdf.format(lastDate.getTime());
    return str;
}
 
def tomorrow(){
    String str = "";
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    Calendar lastDate = Calendar.getInstance();
    lastDate.add(Calendar.DATE, 1);
    str = sdf.format(lastDate.getTime());
    return str;
}
 
def yesterdayOfThreeMonthsAgo(){
    String str = "";
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    Calendar lastDate = Calendar.getInstance();
    lastDate.add(Calendar.MONTH, -3);
    lastDate.add(Calendar.DATE, -1);
    str = sdf.format(lastDate.getTime());
    return str;
}
 
def theFirstDayOfTwoMonthsAgo(){
    String str = "";
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    Calendar lastDate = Calendar.getInstance();
    lastDate.add(Calendar.MONTH, -2);
    lastDate.set(Calendar.DATE, 1);
    str = sdf.format(lastDate.getTime());
    return str;
}
 
def theLastDayOfTwoMonthsAgo(){
    String str = "";
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    Calendar lastDate = Calendar.getInstance();
    lastDate.add(Calendar.MONTH, -2);
    lastDate.set(Calendar.DATE, 1);
    lastDate.roll(Calendar.DATE, -1);
    str = sdf.format(lastDate.getTime());
    return str;
}
 
def theFirstDayOfThreeMonthsAgo(){
    String str = "";
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    Calendar lastDate = Calendar.getInstance();
    lastDate.add(Calendar.MONTH, -3);
    lastDate.set(Calendar.DATE, 1);
    str = sdf.format(lastDate.getTime());
    return str;
}
 
def theFirstDayOfSixMonthsAgo(){
    String str = "";
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    Calendar lastDate = Calendar.getInstance();
    lastDate.add(Calendar.MONTH, -6);
    lastDate.set(Calendar.DATE, 1);
    str = sdf.format(lastDate.getTime());
    return str;
}
 
def tomorrowOfLastYear(){
    String str = "";
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    Calendar lastDate = Calendar.getInstance();
    lastDate.add(Calendar.YEAR, -1);
    lastDate.add(Calendar.DATE, 1);
    str = sdf.format(lastDate.getTime());
    return str;
}
 
def theSameDayOfThisMonthThreeYearsAgo(){
    String str = "";
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    Calendar lastDate = Calendar.getInstance();
    lastDate.add(Calendar.YEAR, -3);
    str = sdf.format(lastDate.getTime());
    return str;
}
 
def theFirstDayOfThisMonthThreeYearsAgo(){
    String str = "";
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    Calendar lastDate = Calendar.getInstance();
    lastDate.add(Calendar.YEAR, -3);
    lastDate.set(Calendar.DATE, 1);
    str = sdf.format(lastDate.getTime());
    return str;
}
 
def theFirstDayOfThreeYearsAgo(){
    String str = "";
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    Calendar lastDate = Calendar.getInstance();
    lastDate.add(Calendar.YEAR, -3);
    lastDate.set(Calendar.MONTH, 0);
    lastDate.set(Calendar.DATE, 1);
    str = sdf.format(lastDate.getTime());
    return str;
}
 
def theFirstDayOfThisYear(){
    String str = "";
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    Calendar lastDate = Calendar.getInstance();
    lastDate.set(Calendar.MONTH, 0);
    lastDate.set(Calendar.DATE, 1);
    str = sdf.format(lastDate.getTime());
    return str;
}
 
def theLastDayOfLastYear(){
    String str = "";
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    Calendar lastDate = Calendar.getInstance();
    lastDate.add(Calendar.YEAR, -1);
    lastDate.set(Calendar.MONTH, 11);
    lastDate.set(Calendar.DATE, 31);
    str = sdf.format(lastDate.getTime());
    return str;
}
 
def theFirstDayOfTheQuarter(){
    String str = "";
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    Calendar lastDate = Calendar.getInstance();
    int i = 0
    int j = 0
    int month = lastDate.get(Calendar.MONTH)
    if (month >= 1 && month <= 3) {
        j = 0;
    }
    if (month >= 4 && month <= 6) {
        j = 3;
    }
    if (month >= 7 && month <= 9) {
        j = 6;
    }
    if (month >= 10 && month <= 12) {
        j = 9;
    }
    lastDate.set(Calendar.MONTH, j);
    lastDate.set(Calendar.DATE, 1);
    str = sdf.format(lastDate.getTime());
    return str;
}
 
def theLastDayOfLastQuarter(String theFirstDayOfTheQuarter){
    String str = "";
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    Date date = sdf.parse(theFirstDayOfTheQuarter)
    Calendar lastDate = Calendar.getInstance();
    lastDate.setTime(date);
    lastDate.add(Calendar.MONTH, -1);
    lastDate.roll(Calendar.DATE, -1);
    str = sdf.format(lastDate.getTime());
    return str;
}
 
def aYearAgoAfterTheLastDayOfLastQuarter(String theFirstDayOfTheQuarter){
    String str = "";
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    Date date = sdf.parse(theFirstDayOfTheQuarter)
    Calendar lastDate = Calendar.getInstance();
    lastDate.setTime(date);
    lastDate.add(Calendar.YEAR, -1);
    str = sdf.format(lastDate.getTime());
    return str;
}
 
def theFirstDayOfLastQuarter(String theFirstDayOfTheQuarter){
    String str = "";
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    Date date = sdf.parse(theFirstDayOfTheQuarter)
    Calendar lastDate = Calendar.getInstance();
    lastDate.setTime(date);
    lastDate.add(Calendar.MONTH, -3);
    str = sdf.format(lastDate.getTime());
    return str;
}
 
def theLastDayOfTwoQuartersAgo(String theLastDayOfLastQuarter){
    String str = "";
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    Date date = sdf.parse(theLastDayOfLastQuarter)
    Calendar lastDate = Calendar.getInstance();
    lastDate.setTime(date);
    lastDate.add(Calendar.MONTH, -3);
    lastDate.set(Calendar.DATE, 1);
    lastDate.roll(Calendar.DATE, -1);
    str = sdf.format(lastDate.getTime());
    return str;
}
 
def theFirstDayOfSixMonthsAgoAfterTwoQuarters(String theLastDayOfTwoQuartersAgo){
    String str = "";
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    Date date = sdf.parse(theLastDayOfTwoQuartersAgo)
    Calendar lastDate = Calendar.getInstance();
    lastDate.setTime(date);
    lastDate.add(Calendar.MONTH, -8);
    lastDate.set(Calendar.DATE, 1);
    str = sdf.format(lastDate.getTime());
    return str;
}
 
def theFirstDayOfThisMonthLastYear(){
    String str = "";
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    Calendar lastDate = Calendar.getInstance();
    lastDate.add(Calendar.YEAR, -1);
    lastDate.set(Calendar.DATE, 1);
    str = sdf.format(lastDate.getTime());
    return str;
}
 
def theFirstDayOfLastYear(){
    String str = "";
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    Calendar lastDate = Calendar.getInstance();
    lastDate.add(Calendar.YEAR, -1);
    lastDate.set(Calendar.MONTH,0)
    lastDate.set(Calendar.DATE, 1);
    str = sdf.format(lastDate.getTime());
    return str;
}
 
def theLastDayOfLastWeek(){
    String str = "";
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    Calendar lastDate = Calendar.getInstance();
    lastDate.add(Calendar.WEEK_OF_MONTH,-1);
    lastDate.set(Calendar.DAY_OF_WEEK, Calendar.SATURDAY);
    str = sdf.format(lastDate.getTime());
    return str;
}
 
def lastMarketClose(){
    String str = "";
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    Calendar lastDate = Calendar.getInstance();
    String ss = lastDate.get(Calendar.DAY_OF_WEEK)
    if ("1".equals(ss)){
        lastDate.add(Calendar.WEEK_OF_MONTH,-1);
        lastDate.set(Calendar.DAY_OF_WEEK, Calendar.FRIDAY)
    }
    if ("7".equals(ss)){
        lastDate.set(Calendar.DAY_OF_WEEK, Calendar.FRIDAY)
    }
    str = sdf.format(lastDate.getTime());
    return str;
}
 
def lastMarketCloseMinus2Days(){
    String str = "";
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    Calendar lastDate = Calendar.getInstance();
    lastDate.add(Calendar.DATE, -2);
    String ss = lastDate.get(Calendar.DAY_OF_WEEK)
    if ("1".equals(ss) ){
        lastDate.add(Calendar.WEEK_OF_MONTH,-1);
        lastDate.set(Calendar.DAY_OF_WEEK, Calendar.FRIDAY)
    }
    if ("7".equals(ss)){
        lastDate.set(Calendar.DAY_OF_WEEK, Calendar.FRIDAY)
    }
    str = sdf.format(lastDate.getTime());
    return str;
}
 
def twoYearsAgoOfLastMarketCloseMinus2Days(String lastMarketCloseMinus2Days){
    String str = "";
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    Date date = sdf.parse(lastMarketCloseMinus2Days)
    Calendar lastDate = Calendar.getInstance();
    lastDate.setTime(date);
    lastDate.add(Calendar.YEAR, -2)
    lastDate.add(Calendar.DATE, 1);
    str = sdf.format(lastDate.getTime());
    return str;
}
 
def yesterdayOfLastMarketClose(String lastMarketClose){
    String str = "";
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    Date date = sdf.parse(lastMarketClose)
    Calendar lastDate = Calendar.getInstance();
    lastDate.setTime(date);
    lastDate.add(Calendar.DATE, -1);
    str = sdf.format(lastDate.getTime());
    return str;
}
 
def aMonthAgoOfLastMarketClose(String lastMarketClose){
    String str = "";
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    Date date = sdf.parse(lastMarketClose)
    Calendar lastDate = Calendar.getInstance();
    lastDate.setTime(date);
    lastDate.add(Calendar.MONTH, -1)
    lastDate.add(Calendar.DATE, 1);
    str = sdf.format(lastDate.getTime());
    return str;
}
 
def threeMonthsAgoOfLastMarketClose(String lastMarketClose){
    String str = "";
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    Date date = sdf.parse(lastMarketClose)
    Calendar lastDate = Calendar.getInstance();
    lastDate.setTime(date);
    lastDate.add(Calendar.MONTH, -3)
    lastDate.add(Calendar.DATE, 1);
    str = sdf.format(lastDate.getTime());
    return str;
}
 
def threeYearsAgoOfLastMarketClose(String lastMarketClose){
    String str = "";
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    Date date = sdf.parse(lastMarketClose)
    Calendar lastDate = Calendar.getInstance();
    lastDate.setTime(date);
    lastDate.add(Calendar.YEAR, -3)
    lastDate.add(Calendar.DATE, 1);
    str = sdf.format(lastDate.getTime());
    return str;
}

  

posted on   张缤分  阅读(371)  评论(0编辑  收藏  举报

编辑推荐:
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
阅读排行:
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 25岁的心里话
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 按钮权限的设计及实现

导航

< 2025年3月 >
23 24 25 26 27 28 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 1 2 3 4 5

统计

点击右上角即可分享
微信分享提示