User-715140818 posted
I am working on globalization project.In some scenario I want to convert date in european format and sometimes in US format.
I have developed method as follow.
public static string
ToCultureDate(object
oValue,string culture)
{
System.Threading.Thread.CurrentThread.CurrentCulture
= cultureinfo;
CultureInfo
cultureinfo = CultureInfo.CreateSpecificCulture(culture);
DateTime date
= Convert.ToDateTime(oValue);
return date.ToString();
}
In this method I try to pass date as object and culture as en-US or fr-FR and accordingly I should get short date format.
But I am getting error Unable to cast object of type 'System.Web.UI.WebControls.Label' to type 'System.IConvertible'.
Actually I am passing object as date and that date is stored in label.
Above method is called as under
lblPickupdate.Text=ToCultureDate(lblPickupdate,languageCulture);
where lblPickupdate is label which holds date.