Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Date format conversion Android

Tags:

java

date

android

I have string form of date:

2011-03-27T09:39:01.607

and I want to format it to March 27, 2011

I am using

DateFormat[] formats = new DateFormat[] {
DateFormat.getDateInstance(), DateFormat.getDateTimeInstance(),
         DateFormat.getTimeInstance(), };
String actDate= formats[0].format(uploadeddate.substring(0,9));

but its not working.

How do I convert to March 27, 2011?

like image 370
Udaykiran Avatar asked Aug 01 '11 09:08

Udaykiran


People also ask

How can I change the date format in Android?

SimpleDateFormat formatter = new SimpleDateFormat("dd-MMM-yyyy hh:mm a"); String date = formatter. format(Date. parse("Your date string")); Hope it will help you.

What is date format in Android Studio?

DateFormat. format("yyyy-MM-dd hh:mm:ss a", new java.


2 Answers

try this

SimpleDateFormat form = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS");
java.util.Date date = null;
try 
{
    date = form.parse("2011-03-27T09:39:01.607");
}
catch (ParseException e) 
{

    e.printStackTrace();
}
SimpleDateFormat postFormater = new SimpleDateFormat("MMMMM dd, yyyy");
String newDateStr = postFormater.format(date);

now newDateStr = March 27, 2011;

like image 73
Niranj Patel Avatar answered Oct 06 '22 23:10

Niranj Patel


String dateimput = "2011-03-27T09:39:01.607"

SimpleDateFormat formatrecived = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");    
SimpleDateFormat formarwanted = new SimpleDateFormat("MMMM dd, yyyy");

Date recived = formatrecived.parse(dateimput);

Date output = formatwanted.format(recived);

Note: dateimput you need to format to yyyy-MM-dd hh:mm:ss using replace and substring

like image 42
PedroAGSantos Avatar answered Oct 07 '22 01:10

PedroAGSantos