基本类型:
byte、short、int、long、float、double、chat、boolean
- string转换int (double、float、Long的大同小异)
String num = "123";
int num2 = 123;
//3种
Integer.parseInt(num); //返回int(生成整型)
Integer.valueOf(num); //返回Integer包装类
Integer.valueOf(num).intValue(); //返回int(生成对象)
- int转换为string (double、float、Long的大同小异)
//toString() 是类的串转换的方法
//3种
String.valueOf(num2);
Integer.toString(num2);
String string2 = num2 + ""; //字符串拼接
- float转换为double
float num3 = 10.00f;
new Float(num3).doubleValue();
- double转换为int
double num4 = 10.0;
new Double(num4).intValue();
- Date基本显示
Date date = new Date();
SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd EE hh:mm:ss.S");
sdf.format(date); //完整的时间
- string转换date
String num5 = "2019-06-03";
DateFormat dateFormat = DateFormat.getDateInstance();//获取日期格式对象方法
long time = dateFormat.parse(num5).getTime();//获取long类型时间
Date date2 = new Date(time);
//重新设置输出格式
String format = DateFormat.getDateTimeInstance().format(date2);