vb.net 日期时间格式字符串?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2956854/
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 Format Strings?
提问by Phil
I have the date format string dd-mm-yy. Please can you tell me how to add hours and minutes to the string (i.e 13-03-2010.21.03) ....
我有日期格式字符串 dd-mm-yy。请您告诉我如何在字符串中添加小时和分钟(即 13-03-2010.21.03)....
DateTime.Today.ToString("dd-mm-yy") ?
回答by Amr Badawy
please check this http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspxand http://www.csharp-examples.net/string-format-datetime/for more information
请检查此http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx和http://www.csharp-examples.net/string-format-datetime/了解更多信息
String.Format("{0:d/M/yyyy HH:mm:ss}", datetime)
回答by GvS
DateTime.Now.ToString("dd-MM-yy.HH.mm")
Change the Today to Now
改变今天到现在
Please note that mm = minutes and MM = months
请注意 mm = 分钟和 MM = 月
回答by Oded
You can use this:
你可以使用这个:
DateTime.Now.ToString("dd-MM-yy.hh.mm")
If you want 24 hours:
如果你想要 24 小时:
DateTime.Now.ToString("dd-MM-yy.HH.mm")
See the MSDNdocumentation.
请参阅MSDN文档。
Note that the format string you first used is incorrect, as mm
stands for minutes so you should have used MM
for months.
请注意,您第一次使用的格式字符串是不正确的,因为它mm
代表分钟,所以您应该已经使用MM
了几个月。
You are also using Today
, which does not have the time component (so it would always be 00:00:00). If you need those (hours, minutes, seconds and milliseconds), you should use Now
.
您也在使用Today
,它没有时间组件(所以它总是 00:00:00)。如果您需要这些(小时、分钟、秒和毫秒),您应该使用Now
.
回答by dxh
DateTime.Now.ToString("dd-MM-yyyy.HH.mm");
mm
is minutes, MM
is months, so your current example is wrong.
mm
是分钟,MM
是几个月,所以你当前的例子是错误的。
Also, note that you need to use Now
rather than Today
, otherwise it'll always be 00.00
另外,请注意,您需要使用Now
而不是Today
,否则它将始终是00.00
回答by kawtousse
DateTime.Now.ToString("dd-MM-yy.HH.mm");
MM for Months mm for minutes
MM 表示月 mm 表示分钟