查找用于将日期解析为字符串的格式
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
除非您有日期超过 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.
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