标签:curMap String 22 format SimpleDateFormat 2021 Date new 07
**
Java获取某个时间段之类的文件或图片
这两天写代码的时候需要完成一个功能,上报一段时间类的图片,
话不多说看代码
public static void disposeXsReport9(List<Map<String, Object>> originData) throws Exception {
List<Map<String, Object>> data = null;
try {
String format = "yyyy-MM-dd HH";
//设置开始时间
Date startTime = new SimpleDateFormat(format).parse("2021-05-16 04");
// 设置结束时间
Date endTime = new SimpleDateFormat(format).parse("2021-07-13 09");
Map<String, File> fileParams = new HashMap<String, File>();
List<Map<String, Object>> datalist = new ArrayList<Map<String, Object>>();
for (int i = 0; i < originData.size(); i++) {
Map<String, Object> curMap = originData.get(i);
Map<String, Object> dataMap = new HashMap<String, Object>();
// 处理attachment
/* String path = (String)curMap.get("PTH"); */
SimpleDateFormat stm = new SimpleDateFormat("yyyy");
String datas = stm.format(new Date());
//设置路径
String path = "D:\\图片数据\\" + datas + "\\" + curMap.get("fadcd") + "\\" + curMap.get("STCD");
int imgtype = (int) curMap.get("imgtype");
String STCD = (String) curMap.get("STCD");
String czcd = (String) curMap.get("hyststats");
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH");
SimpleDateFormat sdfDay1 = new SimpleDateFormat("yyyy-MM-dd");
SimpleDateFormat sdfDay2 = new SimpleDateFormat("yyyy_MM_dd");
SimpleDateFormat sdfDay3 = new SimpleDateFormat("yyyyMMdd");
String curDateStr1 = sdfDay1.format(new Date());
String curDateStr2 = sdfDay2.format(new Date());
String curDateStr3 = sdfDay3.format(new Date());
String path1 = null;
path1 = path;
String curDateStr = sdf.format(startTime);
String cudare=sdf.format(endTime);
// System.out.println(curDateStr);
File stFile = new File(path1);
File[] list = stFile.listFiles();
List<File> files = new ArrayList<File>();
System.out.print(files);
long newestTime = 0;
File newestFile = null;
if (list != null && list.length > 0) {
for (File file : list) {
// System.out.println("filename-------->"+file.getName());
//获取图片最后修改时间
String fileModified = sdf.format(file.lastModified());
Date fileModif1ied = new SimpleDateFormat(format).parse(fileModified);
// System.out.println("fileModified==>"+fileModified);
//设置时间区间
if (fileModif1ied.after(startTime)&&fileModif1ied.before(endTime)) {
//获得时间区间内的图片
files.add(file);
}
}
// 如果当前日期没有图片。获取当天最新一张
/*
* if(files.size()<=0&&null!=newestFile) { files.add(newestFile); }
*/
}
}
标签:curMap,String,22,format,SimpleDateFormat,2021,Date,new,07 来源: https://blog.csdn.net/qwb1693730217/article/details/118995672
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。