如何将日期时间转换为短日期时间 [英] How to convert datetime to short date time

查看:474
本文介绍了如何将日期时间转换为短日期时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用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()


这篇关于如何将日期时间转换为短日期时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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