Thursday, 14 January 2016

Date Time Formatting in C#

1/14/2016 - By Pranav Singh 0

In this article I will show you how you can format your date in a specific date format in c#. This solution you can use in you asp.net, mvc as well as in your windows application. It’s a simple solution.

Date Format
Detail
Output format
d
Short date pattern
6/15/2009
D
Long date pattern
Monday, June 15
f
Full date/time pattern (short time
Monday, June 15, 2009 1:45 PM
F
Full date/time pattern (long time).
Monday, June 15, 2009 1:45:30 PM
g
General date/time pattern (short time)
6/15/2009 1:45 PM
G
General date/time pattern (long time)
6/15/2009 1:45:30 PM
M
Month/day pattern
June
m
Month/day pattern
June
O
Round-trip date/time pattern
2009-06-15T13:45:30.0000000-07:00
o
Round-trip date/time pattern
2009-06-15T13:45:30.0000000-07:00
R
RFC1123 pattern
Mon, 15 Jun 2009 20:45:30 GMT
r
RFC1123 pattern
Mon, 15 Jun 2009 20:45:30 GMT
s
Sortable date/time pattern
2009-06-15T13:45:30
t
Short time pattern
1:45 PM
T
Long date time pattern
1:45:30 PM
u
Universal sortable date/time pattern
2009-06-15 13:45:30Z
U
Universal full date/time pattern
Monday, June 15, 2009 8:45:30 PM
Y
Year month pattern
June, 2009
y
Year month pattern
June, 2009

Now I show you an example. In this example I will show you how you can format the date time string.

Eg.


Console.WriteLine(DateTime.Now.ToString("d"));


Output:

1/15/2016


Tags: ,
About the Author

We are the group of people who are expertise in different Microsoft technology like Asp.Net,MVC,C#.Net,VB.Net,Windows Application,WPF,jQuery,Javascript,HTML. This blog is designed to share the knowledge.

Get Updates

Subscribe to our e-mail newsletter to receive updates.

Share This Post

0 comments:

Please let me know your view

Free Ebooks


About Us

We are the group of people who are expertise in different Microsoft technology like Asp.Net,MVC,C#.Net,VB.Net,Windows Application,WPF,jQuery,Javascript,HTML. This blog is designed to share the knowledge.

Contact Us

For writing article in this website please send request by your

GMAIL ID: dotnetpools@gmail.com

Bugs and Suggestions

As we all know that this website is for sharing knowledge and providing proper solution. So while reading the article is you find any bug or if you have any suggestion please mail us at contact@aspdotnet-pools.com.

Partners


Global Classified : Connectseekers.com
© 2014 aspdotnet-pools.com Designed by Bloggertheme9.
back to top