开发者

how to ask if any date format fit to another?

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


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");
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜