工具类


public static int ceil(int a,int b){
double t1=a;
double t2=b;
int c=(int) Math.ceil(t1/t2);
return c;
}

ceil()方法执行的是向上取整计算,它返回的是大于或等于函数参数,并且与之最接近的整数

3,2---->2



转成负数
public static int zhuanfu(int i){
if(i>0){
String str=String.valueOf(i);
str="-"+str;
return Integer.valueOf(str);
}else return i;
}



获取现在时间
public static String getNowTime(){
Date date = new Date(System.currentTimeMillis());
return FastDateFormat.getInstance("yyyyMMddHHmmss").format(date);
}




1-10之间随机取6位数
public static String getRandom(long l){
char[] randoms = {'1', '2', '3', '4', '5', '6', '7', '8', '9'};
Random random = new Random(l);
StringBuffer ret = new StringBuffer();
for (int i = 0; i < 6; i++) {
ret.append(randoms[random.nextInt(randoms.length)]);
}
random = null;
return ret.toString();
}



获取年份
public static int getYear(Date date){
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
return calendar.get(Calendar.YEAR);
}



获取星期数
public static int getWeekNumber(Date date) {
Calendar calendar = Calendar.getInstance();
calendar.setFirstDayOfWeek(Calendar.MONDAY);

calendar.setTime(date);
return calendar.get(Calendar.WEEK_OF_YEAR);
}



public static Date getFirstDayOfWeek(Date date) {
Calendar c = new GregorianCalendar();
c.setFirstDayOfWeek(Calendar.MONDAY);
c.setTime(date);
c.set(Calendar.DAY_OF_WEEK, c.getFirstDayOfWeek()); // Monday
return c.getTime();
}

public static Date getLastDayOfWeek(Date date) {
Calendar c = new GregorianCalendar();
c.setFirstDayOfWeek(Calendar.MONDAY);
c.setTime(date);
c.set(Calendar.DAY_OF_WEEK, c.getFirstDayOfWeek() + 6); // Sunday
return c.getTime();
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值