Various Date Formats

Would like to share the following for handling different date formats in asp.net

I have a textbox, label and a button control to input, display the result

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;


protected void BtnDisplay_Click(object sender, EventArgs e)
{
lblOutput.Text = txtInput.Text;
DateTime dt = Convert.ToDateTime(txtInput.Text);
lblOutput.Text = dt.ToString("MM/dd/yyyy");
Response.Write("yyyy/mm/dd format --->" + dt.ToString("yyyy/MM/dd"));
Response.Write("yyyy-mm-dd ----->" + dt.ToString("yyyy-MMM-dd"));
}

Input
------
2010/12/31
lable will display 12/31/2010

Output
------
Format yyyy/MM/dd

2010/12/31

Format yyyy-MMM-dd
2010-Dec-31


Comments

No responses found. Be the first to comment...


  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: