How to
convert dd-mm-yyyy into dd/mm/yyyy in ASP.NET using C#/VB.NET
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>How to
convert dd-mm-yyyy into dd/mm/yyyy in ASP.NET using C#/VB.NET</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="txtDate"
runat="server"></asp:TextBox><br />
<asp:Label ID="lblDate"
runat="server"></asp:Label><br />
<asp:Button ID="btnConvert"
Text="Convert"
runat="server"
onclick="btnConvert_Click"
/>
</div>
</form>
</body>
</html>
|
In C#:
using System.Globalization;
public partial class DateConversion : System.Web.UI.Page
{
#region How to convert dd/mm/yyyy into dd-mm-yyyy
protected
void btnConvert_Click(object sender, EventArgs e)
{
DateTime dt = DateTime.ParseExact(txtDate.Text,
"dd/MM/yy", CultureInfo.InvariantCulture);
lblDate.Text =
dt.ToString("dd-MM-yyyy");
}
#endregion
}
|
In VB.NET:
Imports System.Globalization
Partial Public Class DateConversion
Inherits
System.Web.UI.Page
#Region "How to convert dd/mm/yyyy into dd-mm-yyyy"
Protected
Sub btnConvert_Click(ByVal
sender As Object,
ByVal e As EventArgs)
Dim dt As DateTime = DateTime.ParseExact(txtDate.Text,
"dd/MM/yy", CultureInfo.InvariantCulture)
lblDate.Text =
dt.ToString("dd-MM-yyyy")
End
Sub
#End Region
End Class
|
Output:
No comments:
Post a Comment