日期與字符串類型間轉換,百分比與數字類型間轉換

//字符串轉換爲日期

SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

sdf.parse("2010-09-04");

//日期轉換爲字符串

Date date = new Date();

String datestr = sdf.format(date);

//百分比轉換爲數字

 String a="70%";
String c;

NumberFormat format=NumberFormat.getInstance();
String sa=format.parse(a)+"";
float fa=Float.parseFloat(sa);  

//數字轉換爲百分比

 DecimalFormat df1 = new DecimalFormat("##.00%"); 

 String str=df1.format(0.44);

發佈了21 篇原創文章 · 獲贊 5 · 訪問量 5萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章