1、BigInteger://用于存放大数据
BigInteger b1=newBigInteger("100"); //必须是数字符号会报错
BigInteger b2=newBigInteger("2");
b1.add(b2);
subtract();
multiply();
divide();
2、BigDecimal://用于精确计算
1.创建对象
BigDecimal(double)//不建议用,运算结果不精确
BigDecimal(String);//可以用,但是每次要传字符串给构造函数
static BigDecimalvaluefo (double);//可以,直接传递double数
b1.add(b2);
subtract();
multiply();
divide();
3、Date (util/sql)
Date d = new Date();
long time = d.getTime();//通过时间对象获取到当前时间的毫秒值
long time2 =System.currentTimeMillis();//获取当前的毫秒值
Date d = new Date(214243243243L);
setTime();//修改时间对象,并赋新值
DateFormat()//抽象类
用法:
Date d =new Date()
DateFormat df=DateFormat.getDateInstance(DateFormat.FULL);
DateFormat df=DateFormat.getDateInstance(DateFormat.LONG);
DateFormat df=DateFormat.getDateInstance(DateFormat.MEDIUM);
DateFormat df=DateFormat.getDateInstance(DateFormat.SHORT);
System.out.pirntln(df.format(d)):
DateFormat df=DateFormat.getDateTimeInstance(DateFormat.FULL,DateFormat.FULL);//年月日星期加时间的
Date子类:
SimpleDateFormat
(1),Date d= newDate();
SimpleDateFormat sdf= new SimpleDateFormat("yyyy年MM月dd日HH:mm:ss")
System.out.pirntln(sdf.format(d)):
(2),String time="2014年8月2日16:25:59";
SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日HH:mm:ss")
Date d = sdf.parse(time);//将时间字符串转换为日期
4、calendar抽象类
Calendar c=Calendar.getInstance();
int year=c.get(Calendar.YEAR);//获取年份 括号中也可以是1
int month=c.get(Calendar.MONTH);//获取月份(少一个0开始的)
int z=c.get(3);//获取一年的多少个星期
int day=c.get(Calendar.DAY_OF_MONTH);
int week=c.get(Calendar.DAY_OF_WEEK);//问题,国外是周六第七天,周日第一天
要写方法解决:public Static String getWeek(int week){
String [] s=["","星期日","星期一","星期二","星期三","星期四","星期五","星期六"];
return s[week];
}
getNum(int num){
if(num>9)
return num+"";
}else{ return'0'+num}
c.add(Calendar.YEAR,1);//向后加一年,-1是向前减一年