首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > 移动开发 >

自各儿写的,只做记录而已

2012-08-25 
自己写的,只做记录而已package com.android.dateformatimport java.text.DateFormatimport java.util.Da

自己写的,只做记录而已
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)

热点排行