日付小総合

2874 ワード


public static void main(String[] args) {

		long ltoday = System.currentTimeMillis();
		// long lyesday = ltoday-24*60*60*1000l;
		long l7day = ltoday - 7 * 24 * 60 * 60 * 1000l;
		//   
		long lyesday = ltoday-24*60*60*1000l;
		java.sql.Timestamp todaytimes = new java.sql.Timestamp(ltoday);
		// java.sql.Timestamp yesdaytimes = new java.sql.Timestamp(lyesday);
		java.sql.Timestamp day7times = new java.sql.Timestamp(l7day);
		java.sql.Timestamp yes = new java.sql.Timestamp(lyesday);
		//     
		String day7 = day7times.toString().substring(0, 10).replace("-", "");
		//   
		String today = todaytimes.toString().substring(0, 10).replace("-", "");
		//   
		String yesday = yes.toString().substring(0, 10).replace("-", "");
		SimpleDateFormat sdfInput = new SimpleDateFormat("yyyyMMdd");
		Calendar calendar = Calendar.getInstance();
		Date date_s = new Date();
		try {
			date_s = sdfInput.parse(today);
		} catch (ParseException e) {
			e.printStackTrace();
		}
		calendar.setTime(date_s);
		int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK);
		//System.out.println(today);
		// System.out.println(dayOfWeek-1);
		// System.out.println(dayNames[dayOfWeek-1]);
		boolean dayOrWeek = false;
		//   
		String sql_client_all = "select p_type,sum(u_1) as u_1 from T_STAT  where (p_type=6 or p_type=1 or p_type=8) and date_format(logday,'%Y%m%d')<'"+today+"' group by p_type order by logday desc";
		//   
		String sql_client_day = "select pt,zpt,p_type,sum(u_1) as u_1 from T_STAT  where (p_type=6 or p_type=1 or p_type=8) and date_format(logday,'%Y%m%d')='"+yesday+"' group by p_type,pt,zpt order by pt,zpt";
		
		String sql_client_week = "select p_type,sum(u_1) as u_1 from T_CLIENT  where (p_type=6 or p_type=1 or p_type=8) and date_format(logday,'%Y%m%d')>='"+day7+"' and date_format(logday,'%Y%m%d')<'"+today+"' group by p_type order by logday desc";
		
		if ((dayOfWeek - 1) == 1) {
			dayOrWeek = true;
		}
		SimpleDateFormat to_day = new SimpleDateFormat("MM.dd:");
		Date time = new Date(lyesday) ;   
		//System.out.println(time+","+(time.getDay()-1)+" "+time.getDate()+" "+time.getHours()+" "+time.getMinutes()+" "+time.getSeconds()+" ");
		//System.out.println(tim);
		//System.out.println(to_day.format(time));
		sms_day_week(sql_client_day,sql_client_week,sql_client_all,dayOrWeek,to_day.format(time));
		
			
	}