我有一个时间戳,我想将其表示为两行。目前,我正在使用“timeStamp.ToString("dd/MM/yyyy\n hh:mm:ss tt")。”
我想为此保留文化,以便在关注全局化时正确显示此时间戳。
有没有简单的方法可以做到这一点?或者,我是否需要做类似的事情... string.Format("{0}\n{1}", timeStamp.Date.ToString(), timeStamp.Time.ToString() ); ?
谢谢
最佳答案
您可以使用 Date and Time Format Strings格式化 DateTime自定义方式的值:
string result = string.Format("{0:d}\n{0:T}", timestamp);
// result == "6/15/2009\n1:45:30 PM" (en-US)
// result == "15.06.2009\n13:45:30" (de-DE)
关于c# - DateTime 到字符串,在保留文化的同时将换行符格式化为字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5385292/