如何获取DateTime的字符串格式。

编程入门 行业动态 更新时间:2024-10-26 17:28:55
本文介绍了如何获取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的字符串格式。

本文发布于:2023-11-22 15:20:27,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1617951.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字符串   格式   DateTime

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!