显示月份的名称

时间:2015-07-21 21:00:37

标签: android eclipse

我正在创建一个应用程序,我必须显示健身乐队的最新更新,以获取日期:

SQLiteDatabase sql2 = new SaveDataBase.SaveDateBaseHelp(this).getWritableDatabase();

Cursor select = sql2.rawQuery("SELECT pedometer_year, pedometer_month, pedometer_day from db_pedometer_info WHERE _id = (SELECT _id FROM db_pedometer_info ORDER BY _id DESC LIMIT 1); ", null);

try {
    if(select != null && select.getCount() == 1) {
        select.moveToLast();                
        String year = select.getString(select.getColumnIndex("pedometer_year"));
        String month = select.getString(select.getColumnIndex("pedometer_month"));
        String day = select.getString(select.getColumnIndex("pedometer_day"));                          
        Globals.lastUpdateDate = day + "-" + month + "-" +year;                    
    }
}
这告诉我类似于" 11-07-2015" 我想要这样的东西" 2015年7月11日"

3 个答案:

答案 0 :(得分:1)

您可以使用SimpleDateFormat将字符串转换为日期。然后,您可以按照您希望的方式重新格式化日期。

try
{

}
catch (SomeSpecificException spex)
{
    var exception = new Exception();
    exception.Data.Add("Something", "Specific");
    throw exception;
}

答案 1 :(得分:0)

String[] months = new String[] {
    "Jan",
    "Feb",
    "Mar",
    Etc....
};

然后当你去编译日期字符串而不只是month时使用:

months[Integer.valueOf(month)]

答案 2 :(得分:0)

您可以使用此方法

 public String getMonth(String month)
 {
     String [] months = new String[] {
           "Jan", "Feb", "Mar", "Apr", 
           "May", "Jun", "Jul", "Aug", 
           "Sep", "Oct", "Nov", "Dec"};
     for (int i = 1; i < 13; i++) {
         int m = Integer.valueOf(month.replaceFirst("^0+(?!$)", ""));
         if (m == i) {
             month = months[i - 1];
             return month;
         }
     }
     return "Wrong Month";
 }