Search code examples
javaandroidparse-platformandroid-dateandroid-dateutils

Putting Date from Parse.com to same type as System Date


I want to ask, how can I put Date from Parse.com (which is in format "Sat Mar 01 15:52:20 GMT+1:00 2014") to same Date type as the date and time in system. Second thing I want to ask is, how to get only for example "month:day:hour:minute:year" from Parse.com even though the Date is given in format as written above.

Thanks for any suggestion!


Solution

  • You just try like this you can achieve the Date format conversion easily...

        String inputPattern = "yyyy-MM-dd hh:mm:ss";
        String outputPattern = "dd-MMM-yyyy   hh:mm a";
        SimpleDateFormat inFormat = new SimpleDateFormat(inputPattern);
        SimpleDateFormat outputFormat = new SimpleDateFormat(outputPattern);
    
        Date date1 = null;
    
        if (date != null) {
            try {
                date1 = inFormat.parse(date);
                str = outputFormat.format(date1);
                Log.d(null, str);
            } catch (ParseException e) {
                e.printStackTrace();
            }
    
        } else {
            str = " ";
        }