1

您好,我是 Android 新手。任何人都可以帮我2012-07-1515 July. 我知道这是通过使用完成的,DateFormater但我不知道它是如何工作的?请帮我找到这个。

4

3 回答 3

1

试试这个。

public static String convertStringToDate(String startDate) throws ParseException
    {
        String myFormatString = "dd-MMM-yyyy"; // Your startDate Format
        SimpleDateFormat df = new SimpleDateFormat(myFormatString);
        Date startingDate = df.parse(startDate);

        DateFormat dateFormat= new SimpleDateFormat("yyyy-MM-dd");  // Date format what you want
        return dateFormat.format(startingDate);
    }
于 2012-07-17T09:46:18.960 回答
1

ii 事情通过使用 subString() 方法来使用它

   String TimeZOne = "2012-07-08" 
    String Year = TimeZOne.substring(0,4); 
    String month = TimeZOne.substring(4,7); 
    String date = TimeZOne.substring(8,10);

    int Month_1 = Integer.parseInt(month);
    String month_String = find_Month(date_1);//call method

    String date_Fromate = date+" "+month_String ; 

//声明方法

public String Date_String(int i){

switch (i) 
                {
                    case (i==1): 
                    {
                        month = "JAN";
                        break;
                    }
                    case (i==2): 
                    {
                        month = "FEB";
                        break;
                    }
                    case (i==3): 
                    {
                        month = "MAR";
                        break;
                    }
                    case (i==4): 
                    {
                        month = "APR";
                        break;
                    }
                    case (i==5): 
                    {
                        month = "MAY";
                        break;
                    }
                    case (i==6): 
                    {
                        month = "JUN";
                        break;
                    }
                    case (i==7): 
                    {
                        month = "JUL";
                        break;
                    }
                    case (i==8): 
                    {
                        month = "AUG";
                        break;
                    }
                    case (i==9): 
                    {
                        month = "SEP";
                        break;
                    }
                    case (i==10): 
                    {
                        month = "OCT";
                        break;
                    }
                    case (i==11): 
                    {
                        month = "NOV";
                        break;
                    }
                    case (i==12): 
                    {
                        month = "DEC";
                        break;
                    }
                }
         return month;
}
于 2012-07-17T10:48:30.800 回答
0

试试这个代码示例

    String date1 = "15 July 2012";
    SimpleDateFormat sdf = new SimpleDateFormat("dd MMM yyyy");
    Date testDate = null;
    try {
        testDate = sdf.parse(date1);
    }catch(Exception ex){
        ex.printStackTrace();
    }
    System.out.println(testDate);

    sdf = new SimpleDateFormat("yyyy-MM-dd");
    date1 = sdf.format(testDate); 
    System.out.println(date1);
于 2012-07-17T09:52:24.297 回答