java 日期做差 : 场景 判断过期
public static String dateDiff(String startTime, String endTime,
String format) {
// 按照传入的格式生成一个simpledateformate对象
SimpleDateFormat sd = new SimpleDateFormat(format);
long nd = 1000 * 24 * 60 * 60;// 一天的毫秒数
long nh = 1000 * 60 * 60;// 一小时的毫秒数
long nm = 1000 * 60;// 一分钟的毫秒数
long ns = 1000;// 一秒钟的毫秒数
long diff;
long day = 0;
long hour = 0;
long min = 0;
long sec = 0;
// 获得两个时间的毫秒时间差异
try {
diff = sd.parse(endTime).getTime() - sd.parse(startTime).getTime();
day = diff / nd;// 计算差多少天
hour = diff % nd / nh + day * 24;// 计算差多少小时
min = diff % nd % nh / nm + day * 24 * 60;// 计算差多少分钟
sec = diff % nd % nh % nm / ns;// 计算差多少秒
} catch (ParseException e) {
e.printStackTrace();
}
return day + "天" + (hour - day * 24) + "小时"
+ (min - day * 24 * 60) + "分钟";
}
分转换为小时天
static String timeStamp(int minute){
String StatusMinute = "";
int day= minute/60/24;
int hour = minute/60%24;
int min= minute % 60;
if (day > 0)
{
StatusMinute= day + "天";
}
if (hour>0)
{
StatusMinute += hour + "小时";
}
if (min>0)
{
StatusMinute += min + "分钟";
}
System.out.println(StatusMinute);
return StatusMinute;
}
拆分数据:
private List<Map<String, Object>> sqlitSql(List<String> str1,String originSql) {
int step = 1000;
int num = str1.size() / step;
if (num > 0) {
num++;
}
List<Map<String, Object>> parkLotList = new ArrayList<Map<String,Object>>();
int n = 0;
for(int i=1; i<=num;i++){
StringBuilder str2 = new StringBuilder() ;
for (int j=n;j<i*step;j++) {
if(j==str1.size()){
break;
}
System.out.println("j+"+j);
str2.append("'");
str2.append(str1.get(j));
str2.append("'");
if(j!=i*step-1&&j!=str1.size()-1){
str2.append(",");
}
}
String parkLotSql = originSql+str2 +") ";
int nu = parkLotSql.length();
List<Map<String, Object>> parkLotList1 = cgyJdbcTemplate.queryForList(parkLotSql);
parkLotList.addAll(parkLotList1);
n=i*step;
}
return parkLotList;
}
生成6位不重复的随机字符:
public String getlinkNo() {
String linkNo = "";
// 用字符数组的方式随机
String model = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
char[] m = model.toCharArray();
for (int j = 0; j < 6; j++) {
char c = m[(int) (Math.random() * 36)];
// 保证六位随机数之间没有重复的
if (linkNo.contains(String.valueOf(c))) {
j--;
continue;
}
linkNo = linkNo + c;
}
return linkNo;
}