将2014年12月17日转换为mm中的mmddy [英] convert December 17, 2014 to mmddyy in C#

查看:133
本文介绍了将2014年12月17日转换为mm中的mmddy的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

2014年12月17日转换为mmddyy in C#

convert December 17, 2014 to mmddyy in C#

推荐答案

您不需要转换。不要尝试使用表示数据的字符串,而不是数据本身。也就是说,您需要使用类型 System.DateTime ,而不是字符串,并且只有当您需要在屏幕上显示它时才会将这些对象显示为字符串(或类似的东西)那)。有时,您需要将输入字符串解析为 DateTime 的实例。



因此,请阅读文档,所有方法 Parse ParseExact TryParse TryParseExact ToString

http://msdn.microsoft.com/en-us/library/system.datetime%28v=vs.110%29.aspx [ ^ ]。



您可以使用 CultureInfo (实现接口 IFormatProvider )参数和/或字符串参数来控制字符串格式。请参阅:

http:// msdn。 microsoft.com/en-us/library/az4se3k1(v=vs.110).aspx [ ^ ],

http://msdn.microsoft.com/en-us/library/8kb3ddd4(v = vs.110)的.aspx [<一个href =http://msdn.microsoft.com/en-us/library/8kb3ddd4(v=vs.110).aspx\"target =_ blanktitle =New Window> ^ ]。



-SA
You don't need "convert". Don't try to work with strings representing data, instead of data itself. That said, you need to work with the the type System.DateTime, not strings, and show such objects as strings only when you need to show it on screen (or something like that). Sometimes, you need to parse input string into the instance of DateTime.

Therefore, read the documentation, all the methods Parse, ParseExact, TryParse, TryParseExact and ToString:
http://msdn.microsoft.com/en-us/library/system.datetime%28v=vs.110%29.aspx[^].

You can use CultureInfo (implementing the interface IFormatProvider) parameters and/or string parameters to control string formatting. Please see:
http://msdn.microsoft.com/en-us/library/az4se3k1(v=vs.110).aspx[^],
http://msdn.microsoft.com/en-us/library/8kb3ddd4(v=vs.110).aspx[^].

—SA


DateTime dt = new DateTime(2008, 3, 9, 16, 5, 7, 123);
String.Format("{0:y yy yyy yyyy}", dt);  // "8 08 008 2008"   year
String.Format("{0:M MM MMM MMMM}", dt);  // "3 03 Mar March"  month
String.Format("{0: d dd ddd dddd}", dt);  // "9 09 Sun Sunday" day
String.Format("{0:h hh H HH}",     dt);  // "4 04 16 16"      hour 12/24
String.Format("{0:m mm}",          dt);  // "5 05"            minute
String.Format("{0:s ss}",          dt);  // "7 07"            second
String.Format("{0:f ff fff ffff}", dt);  // "1 12 123 1230"   sec.fraction
String.Format("{0:F FF FFF FFFF}", dt);  // "1 12 123 123"    without zeroes
String.Format("{0:t tt}",          dt);  // "P PM"            A.M. or P.M.
String.Format("{0:z zz zzz}",      dt);  // "-6 -06 -06:00"   time zone
String.Format("{0:M/d/yyyy}", dt);            // "3/9/2008"
String.Format("{0:MM/dd/yyyy}", dt);          // "03/09/2008"
String.Format("{0:ddd, MMM d, yyyy}", dt);    // "Sun, Mar 9, 2008"
String.Format("{0:dddd, MMMM d, yyyy}", dt);  // "Sunday, March 9, 2008"
String.Format("{0:MM/dd/yy}", dt);            // "03/09/08"
String.Format("{0:MM/dd/yyyy}", dt);          // "03/09/2008"





希望这有助于



Hope this helps


这篇关于将2014年12月17日转换为mm中的mmddy的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆