自各儿写的,只做记录而已
自己写的,只做记录而已
package com.android.dateformat;
import java.text.DateFormat;
import java.util.Date;
public class MyDateFormat {
public String[] Months = {"一月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","十二月"};
public void mydate(){
DateFormat dateTimeFormat = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.SHORT);
long minTimestamp = 444444444;
Date date = new Date(minTimestamp);
int month = date.getMonth()+1;
for (int i = 0; i < Months.length; i++) {
if ((i+1) == month) {
date.setMonth(Integer.parseInt(Months[i]));
}
}
String MyDateStyle = dateTimeFormat.format(date);
System.out.println("日期格式:"+MyDateStyle);
System.out.println("获得月份::"+month);
}
public static void main(String[] args) {
MyDateFormat mMyDateFormat = new MyDateFormat();
mMyDateFormat.mydate();
}
}
输出异常:
Exception in thread "main" java.lang.NumberFormatException: For input string: "一月"
at java.lang.NumberFormatException.forInputString(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at com.android.dateformat.MyDateFormat.mydate(MyDateFormat.java:16)
at com.android.dateformat.MyDateFormat.main(MyDateFormat.java:26)
package com.android.dateformat;
import java.text.DateFormat;
import java.util.Date;
public class MyDateFormat {
public String[] Months = {"一月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","十二月"};
public void mydate(){
DateFormat dateTimeFormat = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.SHORT);
long minTimestamp = 444444444;
Date date = new Date(minTimestamp);
int month = date.getMonth()+1;
for (int i = 0; i < Months.length; i++) {
if ((i+1) == month) {
date.setMonth(Integer.parseInt(Months[i]));
}
}
String MyDateStyle = dateTimeFormat.format(date);
System.out.println("日期格式:"+MyDateStyle);
System.out.println("获得月份::"+month);
}
public static void main(String[] args) {
MyDateFormat mMyDateFormat = new MyDateFormat();
mMyDateFormat.mydate();
}
}
输出异常:
Exception in thread "main" java.lang.NumberFormatException: For input string: "一月"
at java.lang.NumberFormatException.forInputString(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at com.android.dateformat.MyDateFormat.mydate(MyDateFormat.java:16)
at com.android.dateformat.MyDateFormat.main(MyDateFormat.java:26)