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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 14:54:23  来源:igfitidea点击:

DateTime Format Strings?

vb.netdatetimestring-formatting

提问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

回答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 mmstands for minutes so you should have used MMfor 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");

mmis minutes, MMis months, so your current example is wrong.

mm是分钟,MM是几个月,所以你当前的例子是错误的。

Also, note that you need to use Nowrather 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 表示分钟