C# DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss") 不考虑我的格式
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18824263/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss") does not account my format
提问by Doctorslo
This is the code I have:
这是我的代码:
DateTime.Now.AddMinutes(55).ToString("dd/MM/yyyy HH:mm:ss")
The string I get from that code is:
我从该代码中得到的字符串是:
"16.09.2013 19:45:03"
The question is, why the string is not in the format I've provided?
问题是,为什么字符串不是我提供的格式?
采纳答案by Kamil Budziewski
Use this:
用这个:
DateTime.Now.AddMinutes(55).ToString("dd'/'MM'/'yyyy HH:mm:ss")
because /
means default date separator, so it's associated with your current culture. So know it will use always /
here, no matter of current culture.
因为/
意味着默认日期分隔符,所以它与您当前的文化相关联。所以知道它会一直/
在这里使用,无论当前的文化如何。
Read more here at MSDN