- String和int形式互转
String str = "123123";
int anInt = Integer.parseInt(str);
anInt += 1;
System.out.println(anInt);
![在这里插入图片描述](https://img-blog.csdnimg.cn/6eb02ed8c6874a1fa80451cda5987e49.png#pic_center)
int num = 100;
String s = Integer.toString(num);
s += 1;
System.out.println(s);
![在这里插入图片描述](https://img-blog.csdnimg.cn/04e24ea8c8174daf8bff533562ad393a.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBAUnV2aWtf,size_20,color_FFFFFF,t_70,g_se,x_16#pic_center)
- String和Date形式互转
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-mm-dd");
Date date = simpleDateFormat.parse("2019-09-02");
String strDate = simpleDateFormat.format(date);
strDate += 1;
System.out.println(strDate);
![在这里插入图片描述](https://img-blog.csdnimg.cn/f56c87e5481b4eb7a7f73d71d3da55ee.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBAUnV2aWtf,size_20,color_FFFFFF,t_70,g_se,x_16#pic_center)
- String转Date
此处要注意的是String字符串里的日期要严格按照simpleDateFormat
中的格式,且日期符合现实。
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-mm-dd");
String str = "2019-4-23";
Date date = simpleDateFormat.parse(str);
long time = date.getTime();
System.out.println(time);
![在这里插入图片描述](https://img-blog.csdnimg.cn/cd0c8c0f3154412f90764782dd6343d9.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBAUnV2aWtf,size_20,color_FFFFFF,t_70,g_se,x_16#pic_center)