Thursday , April 18 2019
Home / Dot Net / C# / Date Formatting in C#

Date Formatting in C#

Date Formats in C#:

Date Formatting in C# is a date and time format string defines the text representation of a DateTime or DateTimeOffset value that results from a formatting operation . It can also define the representation of a date and time value that is required in a parsing operation in order to successfully convert the string to a date and time. A custom format string consists of one or more custom date and time format specifiers. Any string that is not a standard date and time format string is interpreted as a custom date and time format string.

Below table is the list of formatting characters

Below table output is based on this date

Specifier Description Output
d Short Date 23/09/2016
D Long Date 23 September 2016
t Short Time 22:08
T Long Time 22:08:09
f Full date and time 23 September 2016 22:08
F Full date and time (long) 23September 2016 22:08:09
g Default date and time 23/09/2016 22:08
G Default date and time (long) 23/09/2016 22:08:09
M Day / Month 23 September
r RFC1123 date Fri, 23 Sep 2016 22:08:09 GMT
s Sortable date/time 2016-09-23T22:08:09
u Universal time, local timezone 2016-09-23 22:08:09Z
Y Month / Year September 2016
dd Day 23
ddd Short Day Name Fri
dddd Full Day Name Friday
hh 2 digit hour 10
HH 2 digit hour (24 hour) 22
mm 2 digit minute 08
MM Month 09
MMM Short Month name Sep
MMMM Month name September
ss seconds 09
fff milliseconds 103
FFF milliseconds without trailing zero 103
yy 2 digit year 16
yyyy 4 digit year 2016
: Hours, minutes, seconds separator, e.g. {0:hh:mm:ss} 10:08:09
/ Year, month , day separator, e.g. {0:dd/MM/yyyy} 23/09/2016
. milliseconds separator

if you want to use above table just use the way like below example.

Thanks for reading this Article if you like this article please share with your Friends.

Print Friendly, PDF & Email

Give us your valuable feedback


About Murali

Hello everyone I am Software Developer having 3+ years of Experience in Microsoft Technologies and Others. My skills :-, C#,, SQL SERVER, web services, windows Service,Windows applications,HTML,CSS, JavaScript,JQuery,AnjularJs

Check Also

Remote Validation

How to Use Remote Validation in MVC

Remote Validation Attribute allows us to validate properties values with server callback using AJAX. Remote …