package timeproblem; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; import java.util.Scanner; public class round {     public static void main(String[] args) {         Scanner sc = new Scanner(System.in ); //        String dateStr1 =sc.nextLine() ; //        String dateStr2 = sc.nextLine();         String dateStr1 ="2017/9/7 0:0:0" ;         String dateStr2 ="2017/9/21 0:0:0" ;         SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");             try {             Date date1 = sdf.parse(dateStr1);             Date date2 = sdf.parse(dateStr2);             int i = (int) ((date2.getTime() - date1.getTime()) / (24 * 3600*1000)-1);             System.out.println(i);             Calendar calendar1 = Calendar.getInstance();             calendar1.setTime(date1);             System.out.println(calendar1.get(Calendar.DAY_OF_WEEK));             Calendar calendar2 = Calendar.getInstance();             calendar2.setTime(date2);             int j = 0;             while (calendar1.getTime().getTime() <= calendar2.getTime().getTime()) {                 if (calendar1.get(Calendar.DAY_OF_WEEK) == 5) {                     j++;                 }                 calendar1.add(Calendar.DAY_OF_MONTH, 1);             }             System.out.println(j);         } catch (ParseException e) {             e.printStackTrace();         }     } }
点赞 评论

相关推荐

09-25 00:00
已编辑
电子科技大学 Java
球球与墩墩:这不是前端常考的对象扁平化吗,面试官像是前端出来的 const flattern = (obj) => { const res = {}; const dfs = (curr, path) => { if(typeof curr === 'object' && curr !== null) { const isArray = Array.isArray(curr); for(let key in curr) { const newPath = path ? isArray ? `${path}[${key}]` : `${path}.${key}` : key; dfs(curr[key], newPath); } } else { res[path] = curr } } dfs(obj); return res; }
查看3道真题和解析
点赞 评论 收藏
分享
牛客网
牛客网在线编程
牛客网题解
牛客企业服务