Monday, January 12, 2009

Date-time format in asp.net

The date time string conversion in asp.net is possible usingmethod of date ToString


Dim curdte As DateTime
curdte = Now()
Response.Write("dd-MMM-yyyy : " & curdte.ToString("dd-MMM-yyyy"))

Response.write "<br>"
Response.Write("dddd, dd MMMM yyyy :" & curdte.ToString("dddd, dd MMMM yyyy"))
Response.write "<br>"
Response.Write("MM/dd/yyyy HH:mm:" & curdte.ToString("MM/dd/yyyy HH:mm"))
Response.write "<br>"
Response.Write("MM/dd/yyyy hh:mm " & curdte.ToString("MM/dd/yyyy HH:mm"))

Response.write "<br>"

Response.Write("MMMM dd" & curdte.ToString("MMMM dd"))
Response.write "<br>"
Response.write "<br>"

Response.Write("dddd, dd MMMM yyyy HH:mm:ss :" & curdte.ToString("dddd, dd MMMM yyyy HH:mm:ss"))
Response.write "<BR>"
Response.Write("DateTime.ToString ( 'd' ):" & curdte.ToString("d"))
Response.write "<BR>"

Response.Write("DateTime.ToString ( 'D' ):" & curdte.ToString("D"))
Response.write "<BR>"

Response.Write("DateTime.ToString ( f) :" & curdte.ToString("f"))
Response.write "<BR>"

Response.Write("DateTime.ToString ( F) :" & curdte.ToString("F"))
Response.write "<BR>"
Response.Write("DateTime.ToString ( g) :" & curdte.ToString("g"))
Response.write "<BR>"

Response.Write("DateTime.ToString ( G) :" & curdte.ToString("G"))

///String patterns

d :
Represents the day of the month as a number from 1 through 31. A single-digit day is formatted without a leading zero
dd :
Represents the day of the month as a number from 01 through 31. A single-digit day is formatted with a leading zero
ddd :
Represents the abbreviated name of the day of the week (Mon, Tues, Wed etc)
dddd :
Represents the full name of the day of the week (Monday, Tuesday etc)


h:
12-hour clock hour

hh:
12-hour clock, with a leading 0

H :
24-hour clock hour
HH :
24-hour clock hour, with a leading 0

m :
Minutes
mm :
Minutes with a leading zero
M :
Month number
MM :
Month number with leading zero
MMM :
Abbreviated Month Name
MMMM :
Full month name (e.g. December)
s :
Seconds :
ss :
Seconds with leading zero :
t :
Abbreviated AM / PM (e.g. A or P)
tt :
AM / PM (e.g. AM or PM
y :
Year, no leading zero

yy :
Year, leadin zero (e.g. 2001 would be 01)
yyy :
Year
yyyy :
Year

4 comments:

  1. Thank you very much..

    Your blog is excellent which serves as solution to most of my hidden questions.

    ReplyDelete
  2. Your blog is very very useful to me.

    Thanks
    Anjeswar

    ReplyDelete
  3. Thank you Anjeshwar..

    If you have any queries and suggestions let me know.

    I will definitely work on it

    ReplyDelete