Date Conversion
public class DateAndTimeFormateConvertion {
// Date Conversion 31/11/2014 To 31-Nov-2014
public String DateConvertString(String str)
{
String formattedDate="";
try
{
Date date = new SimpleDateFormat("dd/MM/yyyy").parse(str);
formattedDate = new SimpleDateFormat("dd-MMM-yyyy").format(date);
}
catch(Exception e)
{
Log.v("Exception ", "Date Exception :"+e.getMessage());
}
return formattedDate;
}
// Convert Date 2014/11/31 To 31-Nov-2014
public String DateConvertStringEdit(String str)
{
String formattedDate="";
try
{
Date date = new SimpleDateFormat("yyyy/MM/dd").parse(str);
formattedDate = new SimpleDateFormat("dd-MMM-yyyy").format(date);
}
catch(Exception e)
{
Log.v("Exception ", "Date Exception :"+e.getMessage());
}
return formattedDate;
}
//Convert Date 1/Nov/2014 To 1-11-2014
public String DateConvertInteger(String str)
{
String DateString="";
try
{
SimpleDateFormat format1 = new SimpleDateFormat("dd-MMM-yyyy");
SimpleDateFormat format2 = new SimpleDateFormat("yyyy-MM-dd");
Date date = format1.parse(str);
DateString = format2.format(date);
}
catch(Exception e)
{
Log.v("Exception ", "Date Convertion Exception :"+e.getMessage());
}
return DateString;
}
Time Conversion
//Time Convertion 13:30 To 1:30 PM
public String TimeConversion(String time)
{
String timeCon="";
if(time.equalsIgnoreCase(""))
{
return timeCon;
}
else
{
DateFormat dateFormat = new SimpleDateFormat("hh:mm:ss");
Date date;
try {
date = dateFormat.parse(time);
DateFormat dateFormate1 = new SimpleDateFormat("h:mma");
timeCon = dateFormate1.format(date);//.toLowerCase(); // "12:18am"
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return timeCon;
}
}
}
public class DateAndTimeFormateConvertion {
// Date Conversion 31/11/2014 To 31-Nov-2014
public String DateConvertString(String str)
{
String formattedDate="";
try
{
Date date = new SimpleDateFormat("dd/MM/yyyy").parse(str);
formattedDate = new SimpleDateFormat("dd-MMM-yyyy").format(date);
}
catch(Exception e)
{
Log.v("Exception ", "Date Exception :"+e.getMessage());
}
return formattedDate;
}
// Convert Date 2014/11/31 To 31-Nov-2014
public String DateConvertStringEdit(String str)
{
String formattedDate="";
try
{
Date date = new SimpleDateFormat("yyyy/MM/dd").parse(str);
formattedDate = new SimpleDateFormat("dd-MMM-yyyy").format(date);
}
catch(Exception e)
{
Log.v("Exception ", "Date Exception :"+e.getMessage());
}
return formattedDate;
}
//Convert Date 1/Nov/2014 To 1-11-2014
public String DateConvertInteger(String str)
{
String DateString="";
try
{
SimpleDateFormat format1 = new SimpleDateFormat("dd-MMM-yyyy");
SimpleDateFormat format2 = new SimpleDateFormat("yyyy-MM-dd");
Date date = format1.parse(str);
DateString = format2.format(date);
}
catch(Exception e)
{
Log.v("Exception ", "Date Convertion Exception :"+e.getMessage());
}
return DateString;
}
Time Conversion
//Time Convertion 13:30 To 1:30 PM
public String TimeConversion(String time)
{
String timeCon="";
if(time.equalsIgnoreCase(""))
{
return timeCon;
}
else
{
DateFormat dateFormat = new SimpleDateFormat("hh:mm:ss");
Date date;
try {
date = dateFormat.parse(time);
DateFormat dateFormate1 = new SimpleDateFormat("h:mma");
timeCon = dateFormate1.format(date);//.toLowerCase(); // "12:18am"
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return timeCon;
}
}
}
No comments:
Post a Comment