问题描述
嗯,这可能是一个非常简单的问题,但我只是注意到我不知道如何将 DateTime.Now
转换为YYMMDD格式,因此例如今天(2009年11月5日)是"091105".
Um, probably a really simple question, but I just noticed that I have no idea on how to convert DateTime.Now
to the format YYMMDD, so for example today (5. November 2009) would be "091105".
我知道 DateTime.Now.ToString()
会有重载,您可以在其中传递格式字符串,但是我找不到正确的格式,例如表示短格式(从2009年的09改为09).
I know there are overloads to DateTime.Now.ToString()
where you can pass in a format string, but I have not found the right format e.g. for short year format (09 instead of 2009).
推荐答案
DateTime.Now.ToString("yyMMdd")
您可能还会发现MSDN上的以下两篇文章很有用,因为它们包含有关DateTime格式的大量信息:
You may also find the following two posts on MSDN useful as they contain a lot of info about DateTime formatting:
这篇关于如何将DateTime对象转换为YYMMDD格式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!