+92 332 4229 857 99ProjectIdeas@Gmail.com

String.Format Function (Vb.net)


String Format function
String.Format() function formats the string according to the user demand in a number of formats discussed below:

Examples
MsgBox(String.Format("The current time is {0:T}", DateTime.Now))
The message box will show the current Time
i.e. "The current time is 2:39:06 AM". 

MsgBox(String.Format("Today is {0:D}", DateTime.Now))
The message box will show the current Date
i.e. "Today is Sunday, August 15, 2010".

MsgBox(String.Format("10 in Currency {0:C}", 10))
The message box will show the specified value as currency
i.e. "10 in Currency $10.00".

MsgBox(String.Format("1 in Percentage {0:P}", 1))
The message box will show the specified value as percentage 
i.e. "1 in Percentage 100.00 %".

MsgBox(String.Format("{0:y yy yyy yyyy}"DateTime.Now))
This message box will display year in 4 different formats
i.e. 10 10 2010 2010

MsgBox(String.Format("{0:d dd ddd dddd}"DateTime.Now))
This message box will display day in 4 different formats
i.e. 15 15 Sun Sunday

MsgBox(String.Format("{0:M MM MMM MMMM}"DateTime.Now))
This message box will display month in 4 different formats
i.e. 8 08 Aug August

MsgBox(String.Format("{0:h hh H HH}"DateTime.Now))
This message box will display hour in 4 different formats
i.e. 2 02 2 02

MsgBox(String.Format("{0:m mm}"DateTime.Now))
This message box will display minute in 2 different formats
i.e. 56 56

MsgBox(String.Format("{0:s ss}"DateTime.Now))
This message box will display second in 2 different formats
i.e. 25 25

MsgBox(String.Format("{0:t tt}"DateTime.Now))
This message box will display AM or PM in 2 different formats
i.e. A AM

MsgBox(String.Format("{0:z zz zzz}"DateTime.Now))
This message box will display the time zone in 4 different formats
i.e. +5 +05 +05:00

MsgBox(String.Format("{0:M/d/yyyy}",DateTime.Now))
The message box will display the date in
M/d/yyyy format
i.e. 8/15/2010     

MsgBox(String.Format("{0:MM/dd/yyyy}",DateTime.Now))
The message box will display the date in
MM/dd/yyyy format
i.e. 08/15/2010

MsgBox(String.Format("{0:ddd, MMM d, yyyy}", DateTime.Now))
The message box will display the date in
ddd/MMM d/yyyy format
i.e. Sun, Aug 15, 2010

MsgBox(String.Format("{0:dddd, MMMM d, yyyy}", DateTime.Now))
The message box will display the date in
dddd/MMMM d/yyyy format
i.e. Sunday, August 15, 2010

MsgBox(String.Format("{0:MM/dd/yy}",DateTime.Now)) 
The message box will display the date in
MM/dd/yy format
i.e. 08/15/10

MsgBox(String.Format("{0:MM/dd/yyyy}",DateTime.Now)) 
The message box will display the date in
MM/dd/yyyy format
i.e. 08/15/2010

MsgBox(String.Format("{0:t}",DateTime.Now))  
The message box will displays “Short Time”
i.e. 3:46 PM

MsgBox(String.Format("{0:T}", DateTime.Now)) 
The message box will displays “Long Time”
i.e. 3:47:50 PM

MsgBox(String.Format("{0:d}", DateTime.Now)) 
The message box will displays “Short Date”
i.e. 8/15/2010 

MsgBox(String.Format("{0:D}", DateTime.Now)) 
The message box will displays “Long Date”
i.e. Sunday, August 15, 2010

MsgBox(String.Format("{0:f}", DateTime.Now)) 
The message box will displays “Long Date with Short Time”
i.e. Sunday, August 15, 2010 3:49 PM

MsgBox(String.Format("{0:F}", DateTime.Now)) 
The message box will displays “Full Date and Time”
i.e. Sunday, August 15, 2010 3:49:49 PM

MsgBox(String.Format("{0:g}", DateTime.Now)) 
The message box will displays “Short Date with Short Time”
i.e. 8/15/2010 3:50 PM 

MsgBox(String.Format("{0:G}", DateTime.Now)) 
The message box will displays “Short Date with Long Time”
i.e. 8/15/2010 3:50:41 PM

MsgBox(String.Format("{0:m}", DateTime.Now)) 
The message box will displays “Month and Day”
i.e. August 15

MsgBox(String.Format("{0:y}", DateTime.Now)) 
The message box will displays “Year and Month”
i.e. August, 2010

MsgBox(String.Format("{0:r}", DateTime.Now)) 
The message box will displays Date and Time in “International time format”:ddd, dd MMM yyyy HH':'mm':'ss 'GMT'
i.e. Sun, 15 Aug 2010 15:52:46 GMT

MsgBox(String.Format("{0:s}", DateTime.Now))
The message box will displays sortable Date and Time in in yyyy'-'MM'-'dd'T'HH':'mm':'ss format
i.e.2010-08-15T15:54:41

MsgBox(String.Format("{0:u}",DateTime.Now)) 
The message box will displays sortable Date and Time in in yyyy'-'MM'-'dd HH':'mm':'ss'Z’ format
i.e.2010-08-15 15:55:59Z


Related articles

0 comments: