开发者

Find format used to parse date into string

DateTime date = new DateTime(1970, 1, 15);
string sdate = date.ToString(value_i_will_forget as开发者_StackOverflow 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.


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)
, also you can add specific DateTimeStyles in third parameter
Try this one
http://msdn.microsoft.com/en-US/library/system.globalization.datetimeformatinfo.shortdatepattern.aspx

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜