I need to format the date into a specific string.
I used SimpleDateFormat
class to format the date using the pattern \"yyyy-MM-dd\'T\'HH:m
Try this
Calendar c = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ", Locale.ENGLISH);
System.out.println("formatted string: "+sdf.format(c.getTime()));
String text = sdf.format(c.getTime());
String result = text.substring(0, 22) + ":" + text.substring(22);
System.out.println("result = " + result);
Try this code
Calendar c = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss Z", Locale.ENGLISH);
String s = sdf.format(c.getTime());
String fDate = s.substring(0, s.length()-2) +":"+s.substring(s.length()-2, s.length());
Log.e("check", "formatted string: "+fDate);