I am using Following codes in C# to display text like 2 DAYS AGO, 43 MINUTES AGO , 8 DAYS AGO and so on depending on the DateTime object in C#. The DateTime Object is in format of " YYYY-MM-DDThh-mm-ss ". But I am not getting any such feature in case of Android. The following is the code snippet I a using in C# . Can any one tell me which class and which Date Formatter can we use in case of android. Please share the code with me. Thank you in advance.
/// <param name="dtObject"></param>
/// <returns></returns>
public static string FormatDateTimeToDisplay(DateTime dtObject)
{
TimeSpan tsObject = DateTime.Now.Subtract(dtObject);
string formatedTime = string.Empty;
//Code to format the text to add number of minutes
if ((tsObject.Days <= 0) && (tsObject.Hours <= 0) && (tsObject.Minutes < 2))
{
formatedTime = tsObject.Minutes + " minute ago";
}
else if ((tsObject.Days <= 0) && (tsObject.Hours <= 0) && (tsObject.Minutes >= 2))
{
formatedTime = tsObject.Minutes + " minutes ago";
}
//Code to format the text to add number of hours
else if ((tsObject.Days <= 0) && (tsObject.Hours < 2))
{
formatedTime = tsObject.Hours + " hour " + tsObject.Minutes + " minutes ago";
}
//Code to format the text to add number of hours and minutes
else if ((tsObject.Days <= 0) && (tsObject.Hours >= 2))
{
formatedTime = tsObject.Hours + " hours " + tsObject.Minutes + " minutes ago";
}
//Code to format the text to add number of days
else if ((tsObject.Days < 2))
{
formatedTime = tsObject.Days + " day ago";
}
else if ((tsObject.Days >= 2) && (tsObject.Days <= 15))
{
formatedTime = tsObject.Days + " days ago";
}
//Code to format the text to add the exact date
else
{
formatedTime = "on " + dtObject.ToString("MM/dd/yyyy") + "";
}
return "(" + formatedTime + ")";
}