将此字符串转换为Datetime C# [英] Convert this string to Datetime C#

查看:69
本文介绍了将此字符串转换为Datetime C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在努力获取将此字符串成功转换为DateTime的代码:

I''m struggling to get code that would successfully convert this string to DateTime:

07/11/11 10h09mn25s



"h","ms"和"s"字符使我的普通转换代码误解了我通常的映射字符.有没有办法(像通配符一样)完全忽略某些字符位置?

例如.说*是我的通配符...



The "h", "ms" & "s" characters cause my normal conversion code to misinterpret my usual mapping characters. Is there a way (like a wild card) to ignore a certain character positions completely?

E.g. say * is my wildcard...

string dateTimeStr = "07/11/11 10h09mn25s"
DateTime.ParseExact(datetimeStr, "dd/MM/yy HH*mm**ss*", System.Globalization.CultureInfo.InvariantCulture);





Thanks!

推荐答案

解析字符串包含转义字符,请尝试:
The parse string includes an escape character, try:
string s = "07/11/11 10h09mn25s";
DateTime dt = DateTime.ParseExact(s, "dd/MM/yy hh\\hmm\\m\\nss\\s", CultureInfo.InvariantCulture);


这篇关于将此字符串转换为Datetime C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆