tags:

views:

34

answers:

1

hi

how to ask in C# Winform if this format: ddd MMM d HH:mm:ss yyyy == true

then convert to dd/MM/yyyy format

thank's in advance

+5  A: 

Use TryParseExact(). Followed by DateTime.ToString() to convert. For example:

    public static string ConvertDate(string arg) {
        DateTime dt;
        if (DateTime.TryParseExact(arg, "ddd MMM d HH:mm:ss yyyy", null, 
              System.Globalization.DateTimeStyles.AssumeLocal, out dt)) {
            return dt.ToString("dd/MM/yyyy");
        }
        // Consider what to return on failure...
        return null;
    }

Test case:

    string s = ConvertDate("Fri Jul 23 10:21:00 2010");
Hans Passant