Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save guilhermecarvalhocarneiro/5d9ca5716a704d32f776 to your computer and use it in GitHub Desktop.
Save guilhermecarvalhocarneiro/5d9ca5716a704d32f776 to your computer and use it in GitHub Desktop.
ConvertDate
public class ConvertDate : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo cultureInfo)
{
try
{
if (value != null)
{
// TODO Verificar como realizar a conversão sem gerar exception
string[] date_time_split = value.ToString().Split('T');
string[] date_split = date_time_split[0].Split('-');
string dateFormat = String.Format("{0}/{1}/{2} {3}", date_split[2], date_split[1], date_split[0], date_time_split[1]);
return dateFormat;
}
return value;
}
catch (Exception e)
{
Debug.WriteLine(String.Format("Erro Convert: {0}", e.ToString()));
return value;
}
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo cultureInfo)
{
try
{
string strValue = value as string;
DateTime resultDateTime;
if (DateTime.TryParse(strValue, out resultDateTime))
{
return resultDateTime;
}
return DependencyProperty.UnsetValue;
}
catch (Exception)
{
return "";
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment