Wednesday, 13 February 2013

Beginning .Net : Create or generate date time object from specified values

We can create date time object by supplying day , month , year , hour , minute and second values. After creating this date time object we can get datetime in our desire format. like short date , long date etc... We are using "ToShortDateString" , "ToLongDateString" , "ToShortTimeString" and "ToLongTimeString" methods.

This is example for this.
In this example we create date time object with day , month , year , hour , minute and second values and print that generated date time on screen.

C#. Net Example :

        DateTime objDateTime = new DateTime(2013, 2, 13, 5, 40, 10);
        Response.Write("<b>Short Date :</b>" + objDateTime.ToShortDateString());
        Response.Write("<br/>");
        Response.Write("<b>Long Date :</b>" + objDateTime.ToLongDateString());
        Response.Write("<br/>");
        Response.Write("<b>Short Time :</b>" + objDateTime.ToShortTimeString());
        Response.Write("<br/>");
        Response.Write("<b>Long Time :</b>" + objDateTime.ToLongTimeString());

VB.Net Examples :

        Dim objDateTime As New DateTime(2013, 2, 13, 5, 40, 10)
        Response.Write("<b>Short Date :</b>" + objDateTime.ToShortDateString())
        Response.Write("<br/>")
        Response.Write("<b>Long Date :</b>" + objDateTime.ToLongDateString())
        Response.Write("<br/>")
        Response.Write("<b>Short Time :</b>" + objDateTime.ToShortTimeString())
        Response.Write("<br/>")
        Response.Write("<b>Long Time :</b>" + objDateTime.ToLongTimeString())

Output :
Create Date Time Object

For more Beginning .Net articles visit this link.  Click Here...

Note : Give us your valuable feedback in comments. Give your suggestions in this article so we can update our articles according to that.


2 comments: