RSS LOGORss   Welcome Guest  Login Register
Welcome to our Blogs
Back Back
Subject


mag
2008/06/09 01:30AM
DateTime Formating and Formats      Number of views: 1802

 

Ok, many many times, I have tried to remember those lines of code but, I always forget, it's nice to have something online to share with others,
System.Globalization.DateTimeFormatInfo dtfi = new System.Globalization.DateTimeFormatInfo();
           dtfi.ShortDatePattern = "dd/MM/yyyy";
           dtfi.LongTimePattern = "hh:mm tt";
           DateTime dt = DateTime.Parse(r);
           r = dt.ToString(dtfi);
To convert a string to DateTime
Dim FromDate As String = Date.Parse(txtFrom.Text.Trim, dtfi).ToString("d/M/yyyy")
 
All the patterns:

MM/dd/yyyy
04/07/2008
dddd, dd MMMM yyyy
Monday, 07 April 2008
dddd, dd MMMM yyyy HH:mm
Monday, 07 April 2008 04:57
dddd, dd MMMM yyyy hh:mm tt
Monday, 07 April 2008 04:57 AM
dddd, dd MMMM yyyy H:mm
Monday, 07 April 2008 4:57
dddd, dd MMMM yyyy h:mm tt
Monday, 07 April 2008 4:57 AM
dddd, dd MMMM yyyy HH:mm:ss
Monday, 07 April 2008 04:57:34
MM/dd/yyyy HH:mm
04/07/2008 04:57
MM/dd/yyyy hh:mm tt
04/07/2008 04:57 AM
MM/dd/yyyy H:mm
04/07/2008 4:57
MM/dd/yyyy h:mm tt
04/07/2008 4:57 AM
MM/dd/yyyy HH:mm:ss
04/07/2008 04:57:34
MMMM dd
April 07
MMMM dd
April 07
yyyy'-'MM'-'dd'T'HH':'mm':'ss.fffffffK
2008-04-07T04:57:34.7106217-04:00
yyyy'-'MM'-'dd'T'HH':'mm':'ss.fffffffK
2008-04-07T04:57:34.7106217-04:00
ddd, dd MMM yyyy HH':'mm':'ss 'GMT'
Mon, 07 Apr 2008 04:57:34 GMT
ddd, dd MMM yyyy HH':'mm':'ss 'GMT'
Mon, 07 Apr 2008 04:57:34 GMT
yyyy'-'MM'-'dd'T'HH':'mm':'ss
2008-04-07T04:57:34
HH:mm
04:57
hh:mm tt
04:57 AM
H:mm
4:57
h:mm tt
4:57 AM
HH:mm:ss
04:57:34
yyyy'-'MM'-'dd HH':'mm':'ss'Z'
2008-04-07 04:57:34Z
dddd, dd MMMM yyyy HH:mm:ss
Monday, 07 April 2008 04:57:34
yyyy MMMM
2008 April
yyyy MMMM
2008 April
 
 

 
The patterns for DateTime.ToString ( 'd' ) :

MM/dd/yyyy
04/07/2008

 
The patterns for DateTime.ToString ( 'D' ) :

dddd, dd MMMM yyyy
Monday, 07 April 2008

 
The patterns for DateTime.ToString ( 'f' ) :

dddd, dd MMMM yyyy HH:mm
Monday, 07 April 2008 04:57
dddd, dd MMMM yyyy hh:mm tt
Monday, 07 April 2008 04:57 AM
dddd, dd MMMM yyyy H:mm
Monday, 07 April 2008 4:57
dddd, dd MMMM yyyy h:mm tt
Monday, 07 April 2008 4:57 AM

 
The patterns for DateTime.ToString ( 'F' ) :

dddd, dd MMMM yyyy HH:mm:ss
Monday, 07 April 2008 04:57:34

 
The patterns for DateTime.ToString ( 'g' ) :

MM/dd/yyyy HH:mm
04/07/2008 04:57
MM/dd/yyyy hh:mm tt
04/07/2008 04:57 AM
MM/dd/yyyy H:mm
04/07/2008 4:57
MM/dd/yyyy h:mm tt
04/07/2008 4:57 AM

 
 
The patterns for DateTime.ToString ( 'G' ) :

MM/dd/yyyy HH:mm:ss
04/07/2008 04:57:34

 
The patterns for DateTime.ToString ( 'm' ) :

MMMM dd
April 07

 
 
The patterns for DateTime.ToString ( 'r' ) :

ddd, dd MMM yyyy HH':'mm':'ss 'GMT'
Mon, 07 Apr 2008 04:57:34 GMT

 
 
The patterns for DateTime.ToString ( 's' ) :

yyyy'-'MM'-'dd'T'HH':'mm':'ss
2008-04-07T04:57:34

 
The patterns for DateTime.ToString ( 'u' ) :

yyyy'-'MM'-'dd HH':'mm':'ss'Z'
2008-04-07 04:57:34Z

 
The patterns for DateTime.ToString ( 'U' ) :

dddd, dd MMMM yyyy HH:mm:ss
Monday, 07 April 2008 04:57:34

 
The patterns for DateTime.ToString ( 'y' ) :

yyyy MMMM
2008 April

 

 

Best wishes,

 

MAG