查找用于将日期解析为字符串的格式

发布于 2024-08-22 02:38:39 字数 480 浏览 2 评论 0原文

DateTime date = new DateTime(1970, 1, 15);
string sdate = date.ToString(value_i_will_forget as string,
    CultureInfo.InvariantCulture);

// some lines later

string format_string = MagicParse(sdate,
    CultureInfo.InvariantCulture);

我有一个任意日期,用 CulturInfo.InvariantCulture 写入字符串。我使用的 .Net 格式 - 例如 "d" - 现在已被遗忘。

但我确实知道该字符串没有改变,它仍然有效并且仍然具有不变的文化。我正在寻找 MagicParse 函数来提取用于写入格式化日期的格式字符串。

DateTime date = new DateTime(1970, 1, 15);
string sdate = date.ToString(value_i_will_forget as string,
    CultureInfo.InvariantCulture);

// some lines later

string format_string = MagicParse(sdate,
    CultureInfo.InvariantCulture);

I have an arbitrary date that I write to a string with CulturInfo.InvariantCulture. The .Net format I use - "d", for example - is now forgotten.

I do know however that the string hasn't changed, its still valid and its still with invariant culture. Im looking for the MagicParse function to extract the format string used to write the formatted date.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

郁金香雨 2024-08-29 02:38:39

除非您有日期超过 12 的日期样本,否则没有任何可行的方法可以保证这种情况的安全。

Unless you have a sample of dates in which the day exceeds 12, then there is no feasible way that this would ever be safe.

垂暮老矣 2024-08-29 02:38:39

DateTime.Parse(your_date_string, CultureInfo.InvariantInfo)
,也可以在第三个参数中添加特定的DateTimeStyles
试试这个
http://msdn.microsoft.com/en- US/library/system.globalization.datetimeformatinfo.shortdatepattern.aspx

DateTime.Parse(your_date_string, CultureInfo.InvariantInfo)
, also you can add specific DateTimeStyles in third parameter
Try this one
http://msdn.microsoft.com/en-US/library/system.globalization.datetimeformatinfo.shortdatepattern.aspx

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文