开发者

how to ask if any date format fit to another?

开发者 https://www.devze.com 2023-01-09 02:42 出处:网络
how to ask in C# Winform if this format: 开发者_运维问答ddd MMM d HH:mm:ss yyyy == true then convert to dd/MM/yyyy format

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

精彩评论

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