将日期格式化为特定的ceratin字符 [英] format a date to a ceratin character specific
本文介绍了将日期格式化为特定的ceratin字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
' {2012/12/19 11:59:59 PM}' // 所以日期看起来像这样
我需要将日期选择为以下格式{yymmdd}
所以最初那个日期需要转换为121219
然后需要转换为字符串。
解决方案
你可以通过String.Format()
// 创建日期时间
DateTime dt = new DateTime();
String .Format( {0: yyMMdd},dt);
System.DateTime [ ^ ]结构提供了解析字符串的方法( TryParse () [ ^ ]并将自身格式化为字符串( ToString() [ ^ ])。
将它们结合起来o得到你需要的东西。
所以你需要格式为yyMMdd的日期时间。
使用以下代码
DateTime thisDate1 = DateTime.Now; // 只是设置为当前日期和时间
Console.WriteLine( 格式化日期为: + thisDate1.ToString( yyMMdd)+ ) >;
'{2012/12/19 11:59:59 PM}' //So the date looks like this
I need the date to be selected to the following format {yymmdd}
so initially that date needs to be converted to look like 121219
then needs to be converted to a string.
解决方案
You can do it byString.Format()
// create date time DateTime dt = new DateTime(); String.Format("{0:yyMMdd}", dt);
The System.DateTime[^] structure provides methods to parse strings (TryParse()[^]) and to format itself into a string (ToString()[^]).
Combine them to get what you need.
So you need the datetime in format yyMMdd.
Using the following code
DateTime thisDate1 = DateTime.Now;//Just getting set to the current date and time Console.WriteLine("Formated Date is: " + thisDate1.ToString("yyMMdd") + ".");
这篇关于将日期格式化为特定的ceratin字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文