.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Code Snippets >> DateTime >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

String Format of Date Time Data type in .NET

Posted By:Sajid P K       Posted Date: November 23, 2010    Points: 15    Category: DateTime    URL: http://www.dotnetspark.com  

The Following Segment explain you different Date Time formatters
 

Y - (year)
M - (month)
d - (day)
h - (hour 12)
H - (hour 24)
m - (minute)
s - (second)
f - (second fraction)
F - (second fraction,trailing Zeroes are trimmed)
t - (P.M. or A.M.)
z - (time zone)

 

Some Samples

  1. String.Format("{0:y yy yyy yyyy}", strdt);  =>  "0 10 010 2010" year
  2. String.Format("{0:M MM MMM MMMM}", strdt); =>  "5 05 May May" month
  3. String.Format("{0:d dd ddd dddd}", strdt); =>  "8 08 Sat Saturday" day
  4. String.Format("{0:h hh H HH}", strdt); =>  "9 09 21 21" hour 12/24
  5. String.Format("{0:m mm}", strdt); =>  "6 16" minute
  6. String.Format("{0:s ss}", strdt); =>  "5 15" second
  7. String.Format("{0:f ff fff ffff}", strdt); =>  "1 12 123 1230" sec.fraction
  8. String.Format("{0:F FF FFF FFFF}", strdt); =>  "1 12 123 123" without zeroes
  9. String.Format("{0:t tt}", strdt); =>  "P PM" A.M. or P.M.
  10. String.Format("{0:z zz zzz}", strdt); =>  "-6 -06 -06:00" time zone
  11. String.Format("{0:M/d/yyyy}", strdt); => "5/8/2010"
  12. String.Format("{0:MM/dd/yyyy}", strdt); =>  "05/08/2010"
  13. String.Format("{0:ddd, MMM d, yyyy}", strdt); => "Sat, May 8, 2010"
  14. String.Format("{0:dddd, MMMM d, yyyy}", strdt); => "Saturday, May 8, 2010"
  15. String.Format("{0:MM/dd/yy}", strdt); => "05/08/10"
  16. String.Format("{0:MM/dd/yyyy}", strdt); =>  "05/08/2010"

 


     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend