将日期转换为dd-mm

时间:2014-05-07 07:52:50

标签: android json date

我有一个来自json的格式(" 2014-04-09 00:00:00")的日期,但在应用程序中我只想以这种格式显示(" 09年4月和#34;)。我怎样才能做到这一点。 请帮帮我。

JSON STRING

{
    "NewDataSet": {
        "Table": [
            {
                "Action_Flag": "1",
                "Address": "Sant Vihar, eastern Highhway.",
                "Batch_ID": "33",
                "City": "Gurgaon",
                "Company_Code": "1",
                "Country_Code": "US",
                "Event_ID": "E041402",
                "Event_Name": "Citi Finance",
                "Event_Venue": "kamani",
                "IEvent_Code": "1960",
                "IEvent_Status_Code": "3",
                "Is_Synced": "0",
                "ISponsor_Code": "12",
                "Setup_Date_Time": "2014-04-04 10:00:00",
                "Sponsor_Name": "CitiFinancial",
                "State_Code": "IN",
                "TearDownDateTime": "2014-04-08 21:00:00",
                "TearDownDateTime_Val": "2014-04-08 10:0"
            },
            {
                "Action_Flag": "1",
                "Address": "Vihar Complex, lal Dongarwadi",
                "Batch_ID": "33",
                "City": "Mumbai",
                "Company_Code": "1",
                "Country_Code": "CAN",
                "Event_ID": "E041406",
                "Event_Name": "City",
                "Event_Venue": "bbb",
                "IEvent_Code": "1964",
                "IEvent_Status_Code": "3",
                "Is_Synced": "0",
                "ISponsor_Code": "12",
                "Setup_Date_Time": "2014-04-09 10:00:00",
                "Sponsor_Name": "CitiFinancial",
                "State_Code": "AB",
                "TearDownDateTime": "2014-04-10 11:00:00",
                "TearDownDateTime_Val": "2014-04-10 -1:0"
            },
            {
                "Action_Flag": "1",
                "Address": "Madhuban Colony,Eastern Highwa",
                "Batch_ID": "33",
                "City": "mumbai",
                "Company_Code": "1",
                "Country_Code": "CAN",
                "Event_ID": "E041407",
                "Event_Name": "Roushh",
                "Event_Venue": "Sultan nagar",
                "IEvent_Code": "1965",
                "IEvent_Status_Code": "3",
                "Is_Synced": "0",
                "ISponsor_Code": "10",
                "Setup_Date_Time": "2014-04-09 00:00:00",
                "Sponsor_Name": "Roush Fenway Racing",
                "State_Code": "AB",
                "TearDownDateTime": "2014-04-10 22:00:00",
                "TearDownDateTime_Val": "2014-04-10 10:0"
            },
            {
                "Action_Flag": "1",
                "Address": "Shewan, Holden Nagar.",
                "Batch_ID": "33",
                "City": "Alwatwa",
                "Company_Code": "1",
                "Country_Code": "CAN",
                "Event_ID": "E041408",
                "Event_Name": "SPC",
                "Event_Venue": "Unit-122",
                "IEvent_Code": "1966",
                "IEvent_Status_Code": "3",
                "Is_Synced": "0",
                "ISponsor_Code": "1",
                "Setup_Date_Time": "2014-04-11 10:00:00",
                "Sponsor_Name": "Aflac",
                "State_Code": "MB",
                "TearDownDateTime": "2014-04-11 20:00:00",
                "TearDownDateTime_Val": "2014-04-11 9:0"
            }
        ]
    }
} 

我有一个来自json的格式(" 2014-04-09 00:00:00")的日期,但在应用程序中我只想以这种格式显示(" 09-apr")。我怎样才能做到这一点。 请帮帮我。

2 个答案:

答案 0 :(得分:1)

使用班级SimpleDateFormat。这可能对你有帮助。尝试使用模式dd-MMM

 String format = "dd-MMM";
 SimpleDateFormat sdf = new SimpleDateFormat(format, Locale.US);
 sdf.format(your_date_object_from_JSON);

答案 1 :(得分:0)

使用以下示例。

    String myFormat1 = "dd-MMMM:"; // In which you need put here
            SimpleDateFormat sdf1 = new SimpleDateFormat(myFormat, Locale.US);


            text_time.setText(sdf.format(myCalendar.getTime()));

来自开发者SimpleDateFormate

month in year   (Text)  M:1 MM:01 MMM:Jan MMMM:January MMMMM:J

所以请使用一个MMMM:January