【发布时间】:2012-01-18 05:03:19
【问题描述】:
长话短说,下面的 sn-ps 是关于将文本月份转换为编号月份(例如 Jan -> 1)。没有错误,但最后我一直得到 0 作为 m 的结果。问题出在哪里?
//date1s[] is the result of splitting date1 by spaces (date1 = 1 Jan 2012)
m = convertMonth(date1s[1]); //date1s[1] contains the Month; date1s[0] the date and date1s[2] the year
public int convertMonth(String monw) {
int x = 0;
if (monw == "Jan") {
x = 1;
}
else if (monw == "Feb") {
x = 2;
}
else if (monw == "Mar") {
x = 3;
}
else if (monw == "Apr") {
x = 4;
}
else if (monw == "May") {
x = 5;
}
else if (monw == "Jun") {
x = 6;
}
else if (monw == "Jul") {
x = 7;
}
else if (monw == "Aug") {
x = 8;
}
else if (monw == "Sep") {
x = 9;
}
else if (monw == "Oct") {
x = 10;
}
else if (monw == "Nov") {
x = 11;
}
else if (monw == "Dec") {
x = 12;
}
return x;
}
【问题讨论】: