Date Formatting

  • Thread starter Thread starter Niclas
  • Start date Start date
N

Niclas

Hi,

I want to display a date in UK format (dd/MM/yyyy) and am using a culture
info object for this. using

Convert.ToString(MyDate, _CultInfo)
works fine, besides that the string includes the time as well.

I have tried using

Convert.ToString(MyDate.ToshortDatestring, _CultInfo)

But this will format the date with US format

Any ideas on how to display a short date formatted string in UK format ?

Niclas
 
Hi Niclas,

I think you want to apply the cultureinfo to the thread to be sure it is
formatted for GB. Try the code below and let us know if it helps?

Ken
Microsoft MVP [ASP.NET]


<%@ Page Language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">
Protected Sub Page_Load _
(ByVal sender As Object, _
ByVal e As System.EventArgs)
System.Threading.Thread.CurrentThread.CurrentCulture = _
New Globalization.CultureInfo("en-GB")
System.Threading.Thread.CurrentThread.CurrentUICulture = _
New Globalization.CultureInfo("en-GB")
TextBox1.Text = Now.ToShortDateString
End Sub
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Short date in UK format</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:textbox id="TextBox1" runat="server"></asp:textbox></div>
</form>
</body>
</html>
 
Back
Top