Featured post

Marshmallow Features Point by Point

Android Runtime (“ART”) Improved application performance and lower memory overhead for faster  multi-tasking. Battery Doze...

Showing posts with label Date_Formats_choice. Show all posts
Showing posts with label Date_Formats_choice. Show all posts

Friday, 15 July 2016

Get date as your choice date format

Get Date String from Existing/Current String Date  
==================


public String getDateStringFromFormatString(String strdate,String formate,String formate1) {
    Date date = Calendar.getInstance().getTime();

    if (!strdate.equalsIgnoreCase("")) {
        SimpleDateFormat formatCompare = new SimpleDateFormat(formate1);
        try {
            date = formatCompare.parse(strdate);
        } catch (ParseException e) {
            date = Calendar.getInstance().getTime();
            e.printStackTrace();
        }

    }
    SimpleDateFormat simpleDateFormat = new SimpleDateFormat(formate, Locale.getDefault());
    return simpleDateFormat.format(date);
}


Call
================

getDateStringFromFormatString("","MMM dd, yyyy",""); // get current date in your format

Get date as your choice date format

Get Date String from Existing/Current String Date  
==================


public String getDateStringFromGlobalToFormatString(String strdate,String formate) {
    Date date = Calendar.getInstance().getTime();

    if (!strdate.equalsIgnoreCase("")) {
        SimpleDateFormat formatCompare = new SimpleDateFormat(ConstantValues.str_appointmentStrtEndDateFormat);
        try {
            date = formatCompare.parse(strdate);
        } catch (ParseException e) {
            date = Calendar.getInstance().getTime();
            e.printStackTrace();
        }

    }
    SimpleDateFormat simpleDateFormat = new SimpleDateFormat(formate, Locale.getDefault());
    return simpleDateFormat.format(date);
}


Call
================

getDateStringFromGlobalToFormatString("","MMM dd, yyyy");