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.
Some of my previous C#.Net articles
are as follows: How
to Find Gridview Control on Button Click in Asp.Net C#, How
To Move All Items From One Listbox To Another In C#, Nested
GridView Using c#.Net In Asp.Net, Read
Outlook Email Subject Using c#, How
To Copy File From One Folder (Source) To Another (Target) in Asp.Net Using
C#.Net, Asp.Net
Ajax MaskedEdit With Validation In Asp.Net Using C#, Get
No of Days Between Two Dates Using C# In Asp.Net.
So here is the table to format the date time string as you required.
So here is the table to format the date time string as you required.
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
0 comments:
Please let me know your view