By Nitesh Rathod


2018-08-10 12:01:13 8 Comments

Below is my code but it throws an exception saying that unable to parse date format.

     try{

        DateFormat outputFormat = new SimpleDateFormat("yyyyMMddHHmmss zzzz", Locale.getDefault());
        DateFormat inputFormat = new SimpleDateFormat("yyyy-MM-dd-HH:mm:ss", Locale.getDefault());

        String inputText = channelListArrayList.get(0).getTv().getProgramme().get(j).getStart();
        Date date = inputFormat.parse(inputText);
        String outputText = outputFormat.format(date);

      } catch (Exception e) {
         e.printStackTrace();
      }

2 comments

@Jay Mungara 2018-08-10 12:21:44

I hope you can do it like this,

    oldfmt = "yyyyMMddHHmmss zzzz";
    newfmt = "HH:mm:ss";
    getTimeFromUtc(oldfmt, newfmt, "20180805231400 -0300");

public void getTimeFromUtc(String oldFormat, String newformat, String datetime) {
    SimpleDateFormat inputFormat = new SimpleDateFormat(oldFormat);
    inputFormat.setTimeZone(TimeZone.getTimeZone("GMT"));

    SimpleDateFormat outputFormat = new SimpleDateFormat(newformat, Locale.getDefault());
    TimeZone defaultTimezone = TimeZone.getDefault();
    outputFormat.setTimeZone(defaultTimezone);
    String inputDateStr = datetime;
    Date date = null;
    try {
        date = inputFormat.parse(inputDateStr);
    } catch (ParseException e) {
        e.printStackTrace();
    }
    if (date != null) {
        outputDateStr = outputFormat.format(date);
    }
    Toast.makeText(getApplicationContext(), outputDateStr, Toast.LENGTH_LONG).show();
}

@Shubham Vala 2018-08-10 12:36:29

Try this,

try{

 DateFormat inputFromat = new SimpleDateFormat("yyyyMMddHHmmss zzzz", Locale.getDefault());
 DateFormat outputFormat= new SimpleDateFormat("HH:mm:ss", Locale.getDefault());

 String inputText = channelListArrayList.get(0).getTv().getProgramme().get(j).getStart();
                Date date = inputFormat.parse(inputText);
                String outputText = outputFormat.format(date);
} catch (Exception e) {
        e.printStackTrace();
}

Related Questions

Sponsored Content

31 Answered Questions

[SOLVED] How to get the current time in Python

  • 2009-01-06 04:54:23
  • user46646
  • 2160273 View
  • 1974 Score
  • 31 Answer
  • Tags:   python datetime time

23 Answered Questions

[SOLVED] Convert a Unix timestamp to time in JavaScript

24 Answered Questions

[SOLVED] How do I get time of a Python program's execution?

  • 2009-10-12 23:56:47
  • john2x
  • 621583 View
  • 605 Score
  • 24 Answer
  • Tags:   python time

34 Answered Questions

[SOLVED] Get current time and date on Android

  • 2011-03-20 16:12:25
  • M7M
  • 1120403 View
  • 897 Score
  • 34 Answer
  • Tags:   android date time

16 Answered Questions

[SOLVED] Is there a way to get the source code from an APK file?

1 Answered Questions

[SOLVED] java.text.ParseException while converting string to date

1 Answered Questions

Unparsable date Exception Simple Date Format

2 Answered Questions

[SOLVED] how to format date using SimpleDateFormat

1 Answered Questions

Sponsored Content