如何将日期时间转换为短日期时间

编程入门 行业动态 更新时间:2024-10-28 00:18:58
本文介绍了如何将日期时间转换为短日期时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

如何使用C#代码将2011-07-24 00:00:00.000转换为07-24-2013(MM-DD-YYYY)。请帮帮我

How can I convert 2011-07-24 00:00:00.000 into 07-24-2013(MM-DD-YYYY) in C# code. Please help me

推荐答案

这里的示例使用 C# [ ^ ]& SQL Server [ ^ ] Here samples using C#[^] & SQL Server[^]

尝试执行以下代码 Try to execute below code DateTime thisDate1 = new DateTime(2011, 6, 10); Console.WriteLine("Today is " + thisDate1.ToString("MMMM dd, yyyy") + "."); DateTimeOffset thisDate2 = new DateTimeOffset(2011, 6, 10, 15, 24, 16, TimeSpan.Zero); Console.WriteLine("The current date and time: {0:MM/dd/yy H:mm:ss zzz}", thisDate2);

以下单行代码将帮助您解决问题。 。 。 我将今天的日期时间转换为短日期和短时间。 获取当前日期和时间: Following Single line code will help you out . . . I am Converting TODAY'S date time to short date and short time. To get current date and time: DateTime CurrentDateTime = DateTime.Now;

将今天的DateTime转换为短日期:

To Convert today's DateTime to short date:

string CurrentDate= CurrentDateTime.ToShortDateString();

将今天的DateTime转换为短时间:

To Convert today's DateTime to short time:

string CurrentTime= CurrentDateTime.ToShortTimeString()

更多推荐

如何将日期时间转换为短日期时间

本文发布于:2023-10-23 06:23:17,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1520051.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:日期   时间   转换为   如何将

发布评论

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

>www.elefans.com

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