Wednesday, 29 May 2013

How to use DateTime object and manupulate property of that object using c#

How to use DateTime object and accessing in different-2 format of that object using c#



Step 1 : First create your website in asp.net and create one .aspx page .

Step2  : Open .aspx page source code .cs file




Step 3 : Access different-2 format of datetime object

 //default fomrat of date  
Response.Write(dt.ToString()); 
 
// Accessing only Day month year
Response.Write("<br/>1. " + DateTime.Now.ToString("dd-MM-yyyy"));

 // Accessing only 24 hours minute second
Response.Write("<br/>2. " + DateTime.Now.ToString("HH:mm:ss"));

 // Accessing only 12 hours minute second
Response.Write("<br/>3. " + DateTime.Now.ToString("hh:mm:ss tt"));

 // Accessing full date
 Response.Write("<br/>4. " + DateTime.Now.ToString("dd-MM-yyyy hh:mm:ss tt"));

Response.Write("<br/>5. " + DateTime.Now.ToString("ddd-MMM-yy"));

 Response.Write("<br/>6. " + DateTime.Now.ToString("dddd-MMMM-yyyy"));



Step 4 : This way you can access different-2 format of date time object.

Output will be:

1. 29-05-2013
2. 16:36:10
3. 04:36:10 PM
4. 29-05-2013 04:36:10 PM
5. Wed-May-13
6. Wednesday-May-2013





No comments:

Post a Comment

Thank you for your interest .