WHAT'S NEW?

Converting 2018-02-26 to 26, February 2018 using Java Code

Date Conversions are one of the most important part of an app development. It is also a tricky task for the developer as well, as database needs a different format and client need to be shown the date in some different format.


So following method will help you convert your YYYY-MM-DD format to DD, MM(in words) year format


Lets make a class by name DateConvertor.java


class DateConvertor
{
public static String getFormatedDate(String date)
{
String dat[]=date.split("-");
String year=dat[0];
int m=Integer.parseInt(dat[1]);
String day=dat[2];


String month="";
switch (m) {
case 1:
month="January";
break;
case 2:
month="February";
break;

case 3:
month="March";
break;

case 4:
month="April";
break;

case 5:
month="May";
break;

case 6:
month="June";
break;

case 7:
month="July";
break;

case 8:
month="August";
break;

case 9:
month="September";
break;

case 10:
month="October";
break;

case 11:
month="November";
break;

case 12:
month="December";
break;

default:
break;
}

String fDate=day+", "+month+" "+year;
return fDate;
}
}



Now pass any date in YYYY-MM-DD format and get the formatted date just like that. If you want to learn more about Java click on this link

Now from any place just call the method and get the output

String dt="2018-02-26";
String fDate=DateConvertor.getFormatedDate(dt);


0 comments:

Post a Comment