Escolar Documentos
Profissional Documentos
Cultura Documentos
ToString()CodeProject
Searchforarticles,questions,tips
articles Q&A forums lounge
Introduction
Here is the lot of formats are given for how to use the DateTime.ToString in our C# Project.
Background
The DateTime class is most usefull for our time based programs. But we dont' know how to use the DateTime.ToString
function with appropriate formats. Here I am giving some formats for using DateTime.ToString.
DateTimedt=DateTime.Now;
StringstrDate="";
strDate=dt.ToString("MM/dd/yyyy");//07/21/2007
strDate=dt.ToString("dddd,ddMMMMyyyy");//Saturday,21July2007
strDate=dt.ToString("dddd,ddMMMMyyyyHH:mm");//Saturday,21July200714:58
strDate=dt.ToString("dddd,ddMMMMyyyyhh:mmtt");//Saturday,21July200703:00PM
strDate=dt.ToString("dddd,ddMMMMyyyyH:mm");//Saturday,21July20075:01
strDate=dt.ToString("dddd,ddMMMMyyyyh:mmtt");//Saturday,21July20073:03PM
strDate=dt.ToString("dddd,ddMMMMyyyyHH:mm:ss");//Saturday,21July200715:04:10
strDate=dt.ToString("MM/dd/yyyyHH:mm");//07/21/200715:05
strDate=dt.ToString("MM/dd/yyyyhh:mmtt");//07/21/200703:06PM
strDate=dt.ToString("MM/dd/yyyyH:mm");//07/21/200715:07
strDate=dt.ToString("MM/dd/yyyyh:mmtt");//07/21/20073:07PM
strDate=dt.ToString("MM/dd/yyyyHH:mm:ss");//07/21/200715:09:29
strDate=dt.ToString("MMMMdd");//July21
strDate=dt.ToString("yyyy''MM''dd'T'HH':'mm':'ss.fffffffK");//200707
21T15:11:19.1250000+05:30
http://www.codeproject.com/Articles/19677/FormatsforDateTimeToString 1/4
2/2/2016 FormatsforDateTime.ToString()CodeProject
strDate=dt.ToString("ddd,ddMMMyyyyHH':'mm':'ss'GMT'");//Sat,21Jul200715:12:16GMT
strDate=dt.ToString("yyyy''MM''dd'T'HH':'mm':'ss");//20070721T15:12:57
strDate=dt.ToString("HH:mm");//15:14
strDate=dt.ToString("hh:mmtt");//03:14PM
strDate=dt.ToString("H:mm");//5:15
strDate=dt.ToString("h:mmtt");//3:16PM
strDate=dt.ToString("HH:mm:ss");//15:16:29
strDate=dt.ToString("yyyy''MM''ddHH':'mm':'ss'Z'");//2007072115:17:20Z
strDate=dt.ToString("dddd,ddMMMMyyyyHH:mm:ss");//Saturday,21July200715:17:58
strDate=dt.ToString("yyyyMMMM");//2007July
Hencewecanformatandgettingthedatetimevalue.
License
This article has no explicit license attached to it but may contain usage terms in the article text or the download files
themselves. If in doubt please contact the author via the discussion board below.
Share
EMAIL TWITTER
Hi Viewers,
I wish to all. This is Vinoth. This is where I try to condense everything that you need to know about me.
Blog:
visit my blog
Interests:
I'm passionate about a great many things and continually learning about the things that interest me. They are wearable
computers, User Interface Design, Artificial life, Industrial music.
http://www.codeproject.com/Articles/19677/FormatsforDateTimeToString 2/4
2/2/2016 FormatsforDateTime.ToString()CodeProject
Search Comments Go
My vote of 3
Yogesh Potdar 14May13 1:30
My vote of 3
d347hm4n 26Jun12 6:46
My vote of 1
Member 7823211 27Apr12 1:52
My vote of 1
VMykyt 16Jul09 21:54
Unnecessary apostrophes
PIEBALDconsult 21Jul07 10:11
Really!?
Mark Nischalke 21Jul07 9:35
http://www.codeproject.com/Articles/19677/FormatsforDateTimeToString 3/4
2/2/2016 FormatsforDateTime.ToString()CodeProject
Why?
mav.northwind 21Jul07 8:29
Refresh 1
Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.
http://www.codeproject.com/Articles/19677/FormatsforDateTimeToString 4/4