[英]is there a way to ignore part of a datetime string when using DateTime.TryParseExact?
My datetime string looks like this 我的日期时间字符串看起来像这样
19430403000000-0400
But I only care about the values before the dash (i know its UTC offset, but I don't require that offset value) 但是我只关心破折号之前的值(我知道它的UTC偏移量,但是我不需要该偏移量值)
So I want to use DateTime.TryParseExact if possible since I have a class that already implements it where the user passes the datetime format as string 所以我想尽可能使用DateTime.TryParseExact,因为我有一个已经实现了它的类,其中用户将datetime格式作为字符串传递
So for this I want something like 所以我想要这样的东西
"yyyyMMddhhmmss-####"
where the user can ignore parts of the string format 用户可以忽略部分字符串格式
Is that possible? 那可能吗?
I think I still have to specify the entire format, I just have to use DateTimeOffset instead of DateTime. 我想我仍然必须指定整个格式,我只需要使用DateTimeOffset而不是DateTime。 Seems to parse it alright.
似乎可以解析它了。
string date8 = "19430403000000-0400";
DateTimeOffset result2;
bool parsed = DateTimeOffset.TryParseExact(date8, "yyyyMMddhhmmss zzzz", CultureInfo.InvariantCulture,
DateTimeStyles.AllowWhiteSpaces,
out result2);
string str = "19430403000000-0400";
string output = str.Split("-")[0];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.