我有一个java程序,每天都会手动运行。 现在我想每周创建一个excel文件来写入本周的所有任务
我知道如何每天创建一个文件,如下所示:
if(!IoUtils.fileExist("indicators-" + IoUtils.getCurrentDate() + ".xls")){
IoUtils.createIndicFile("indicators-" + IoUtils.getCurrentDate() + ".xls");
}
else IoUtils.INDIC_FILEPATH = "indicators-" + IoUtils.getCurrentDate() + ".xls";
这是一个以特定格式给出当前日期的函数:
// IoUtils class
public static String getCurrentDate(){
LocalDateTime ldt = LocalDateTime.now();
return DateTimeFormatter.ofPattern("dd-MM-yyyy", Locale.ENGLISH).format(ldt);
}
那么我怎样才能将其更改为每周只创建一个文件?
我还想在文件名中包含月份和周数,如下所示:
// first monday of january 2018
name = "indicators-week1-01-2018"
// second monday of january 2018
name = "indicators-week2-01-2018"
谢谢
最佳答案
Java 提供了java.util.concurrent.ScheduledThreadPoolExecutor,它可以额外安排命令在给定的延迟后运行,或定期执行。
Scheduler.scheduleWithFixedDelay(task, StartDelay, repeatInterval, TimeUnit.MINUTES);
关于java - 每周创建一个文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53516297/