santhosh5
3/15/2019 - 2:40 PM

Converting from Utc to local time using Calendar

2019-03-14T15:03:44.665Z converting the date to 15-Mar_2019 08:01 PM format, not the time stamp

public class DateUtil {

    private static final String TAG = "DateHelper";
    private static final SimpleDateFormat SERVER_DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", Locale.getDefault());
    private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("MMM d yyyy, HH:mm:ss", Locale.getDefault());

    public static String getFormattedDate(String dateString) throws ParseException {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
        SimpleDateFormat output = new SimpleDateFormat("dd-MMM-yyyy hh:mm a");
     /*   SimpleDateFormat output = new SimpleDateFormat("dd-MMM-yyyy");
        SimpleDateFormat time = new SimpleDateFormat("hh:mm ");*/
//        sdf.setTimeZone(TimeZone.getTimeZone("Asia/Kolkata"));
//        sdf.setTimeZone(TimeZone.getDefault());

        Date d = sdf.parse(dateString);
        String formattedTime = output.format(d);

        Date calDate = sdf.parse(dateString);
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(calDate);
        calendar.add(Calendar.HOUR, 5);
        calendar.add(Calendar.MINUTE, 30);

        Date convertedDate = calendar.getTime();
        String convTime = output.format(convertedDate);

        return convTime;
    }
}