本文介绍了如何获取DateTime的字符串格式。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Hello Team, 我知道获取DateTime的格式。 例如: DateTime dt = DateTime.Now; i将获得日期和时间。 但如果我想要日期如28-dec-1980 如何获得它? 请帮助 谢谢 Harshal
Hello Team, I know the format to get the DateTime. for example: DateTime dt = DateTime.Now; i will get Date and Time. But if i want date like 28-dec-1980 how to get it ? Kindly help Thanks Harshal
推荐答案msdn.microsoft/en-us/library/8kb3ddd4(v = vs.110).aspx [ ^ ] 更多说明: msdn.microsoft/en-us/library/az4se3k1(v = vs.110).aspx [ ^ ] www.csharp-examples/string-format-datetime/ [ ^ ] msdn.microsoft/en-us/library/8kb3ddd4(v=vs.110).aspx[^] More Explanation : msdn.microsoft/en-us/library/az4se3k1(v=vs.110).aspx[^] www.csharp-examples/string-format-datetime/[^]
using System; class Program { static void Main() { DateTime time = DateTime.Now; // Use current time string format = " dd-MMM-yyyy"; // Use this format Console.WriteLine(time.ToString(format)); // Write to console } }
class Program { static void Main(string[] args) { string teststring = "abcdefgha"; DateTime date = DateTime.Now; string datetime1 = date.ToShortDateString(); string datetime2 = date.ToLongDateString(); string datetime3 = date.ToString("dd-MM-yyyy"); Console.Write(datetime1); Console.Write(datetime3); Console.ReadKey(); } }
更多推荐
如何获取DateTime的字符串格式。
发布评论