1.數(shù)學(xué)方法
Math.IEEEremainder 求余
Math.max 求兩數(shù)中最大
Math.min 求兩數(shù)中最小
Math.sqrt 求開方
Math.abs(x) 求絕對(duì)值
Math.pow 求某數(shù)的任意次方, 拋出ArithmeticException處理溢出異常
Math.sqrt(x):平方根
Math.pow(x,y):x的y次方
Math.exp 求e的任意次方
Math.log10 以10為底的對(duì)數(shù)
Math.log 自然對(duì)數(shù)
Math.rint 求距離某數(shù)最近的整數(shù)(可能比某數(shù)大彭沼,也可能比它胁ā)
Math.round 同上,返回int型或者long型(上一個(gè)函數(shù)返回double型)
Math.random 返回0,1之間的一個(gè)隨機(jī)數(shù)
2.類型轉(zhuǎn)換
- string轉(zhuǎn)為int:
workticketCount=Integer.parseInt(project.getWorkticketCount()); - int轉(zhuǎn)為float:
actualTotalTime=(float)(currentProcedure.getActualTotalTime()); - string轉(zhuǎn)為float:
float a = Float.parseFloat(name);
3.各種類型取值
double類型: 2.55
float類型: 2.5
int類型: 2
long類型: 255829188
4.示例
private static final SimpleDateFormat simpleDateFormat = new SimpleDateFormat("HH:mm:ss:SSS");
String[] timing1 =simpleDateFormat.format(new Date()).split(":");
int millisecond1 =Integer.parseInt(timing1[3]);
Log.v("時(shí)間_1",millisecond1+"");
String[] timing2 =simpleDateFormat.format(new Date()).split(":");
int millisecond2 =Integer.parseInt(timing2[3]);
Log.v("時(shí)間_2",millisecond2+"");
int millisecond = Math.abs(millisecond2-millisecond1);
Log.v("時(shí)間_3",millisecond+"");
Toast.makeText(activity,"時(shí)間差為:"+ millisecond , Toast.LENGTH_SHORT).show();
5.獲取系統(tǒng)時(shí)間
private static final SimpleDateFormat dateTimeFormat = new SimpleDateFormat("yyyy年MM月dd日 EEEE HH:mm:ss");
String maintainTime=dateTimeFormat.format(new Date());//當(dāng)前系統(tǒng)時(shí)間
Log.v("time_1", maintainTime+"");
Log.v("time_2", SystemClock.currentThreadTimeMillis()+"");
01-16 17:27:21.137 10559-10559/com.jack.workticket V/time_1:2018年10月11日 星期四 15:32:53
01-16 17:27:44.155 10559-10559/com.jack.workticket V/time_2: 7375