Now returns date in invalid format

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi there
This is a production issue. My application is build on .NET Frameword 1.0 form based application.
My application works fine in US.

I used the Now function to get the current system date
I changed my computer locale to UK. My application returns current date in US format instead of the UK format.
Also Cdate function is failing on me.

What I need to do so that when my current locale is UK .NET application date in UK format

Thanks
 
Source:MSDN
-----------

You will need to change the first parameter from "en-US" to UK.

Imports System
Imports System.Globalization
Imports Microsoft.VisualBasic

Public Class SamplesDTFI

Public Shared Sub Main()

' Creates and initializes a DateTimeFormatInfo associated with the
en-US culture.
Dim myDTFI As DateTimeFormatInfo = New CultureInfo("en-US",
False).DateTimeFormat

' Creates a DateTime with the Gregorian date January 3, 2002
(year=2002, month=1, day=3).
' The Gregorian calendar is the default calendar for the en-US
culture.
Dim myDT As New DateTime(2002, 1, 3)

' Displays the format pattern associated with each format
character.
Console.WriteLine("FORMAT en-US EXAMPLE")
Console.WriteLine("CHAR VALUE OF ASSOCIATED PROPERTY, IF ANY")
Console.WriteLine()
Console.WriteLine(" d {0}", myDT.ToString("d"))
Console.WriteLine(" {0} {1}", myDTFI.ShortDatePattern,
"(ShortDatePattern)")
Console.WriteLine()
Console.WriteLine(" D {0}", myDT.ToString("D"))
Console.WriteLine(" {0} {1}", myDTFI.LongDatePattern,
"(LongDatePattern)")
Console.WriteLine()
Console.WriteLine(" f {0}", myDT.ToString("f"))
Console.WriteLine()
Console.WriteLine(" F {0}", myDT.ToString("F"))
Console.WriteLine(" {0} {1}", myDTFI.FullDateTimePattern,
"(FullDateTimePattern)")
Console.WriteLine()
Console.WriteLine(" g {0}", myDT.ToString("g"))
Console.WriteLine()
Console.WriteLine(" G {0}", myDT.ToString("G"))
Console.WriteLine()
Console.WriteLine(" m {0}", myDT.ToString("m"))
Console.WriteLine(" {0} {1}", myDTFI.MonthDayPattern,
"(MonthDayPattern)")
Console.WriteLine()
Console.WriteLine(" M {0}", myDT.ToString("M"))
Console.WriteLine(" {0} {1}", myDTFI.MonthDayPattern,
"(MonthDayPattern)")
Console.WriteLine()
Console.WriteLine(" r {0}", myDT.ToString("r"))
Console.WriteLine(" {0} {1}", myDTFI.RFC1123Pattern,
"(RFC1123Pattern)")
Console.WriteLine()
Console.WriteLine(" R {0}", myDT.ToString("R"))
Console.WriteLine(" {0} {1}", myDTFI.RFC1123Pattern,
"(RFC1123Pattern)")
Console.WriteLine()
Console.WriteLine(" s {0}", myDT.ToString("s"))
Console.WriteLine(" {0} {1}",
myDTFI.SortableDateTimePattern, "(SortableDateTimePattern)")
Console.WriteLine()
Console.WriteLine(" t {0}", myDT.ToString("t"))
Console.WriteLine(" {0} {1}", myDTFI.ShortTimePattern,
"(ShortTimePattern)")
Console.WriteLine()
Console.WriteLine(" T {0}", myDT.ToString("T"))
Console.WriteLine(" {0} {1}", myDTFI.LongTimePattern,
"(LongTimePattern)")
Console.WriteLine()
Console.WriteLine(" u {0}", myDT.ToString("u"))
Console.WriteLine(" {0} {1}",
myDTFI.UniversalSortableDateTimePattern,
"(UniversalSortableDateTimePattern)")
Console.WriteLine()
Console.WriteLine(" U {0}", myDT.ToString("U"))
Console.WriteLine()
Console.WriteLine(" y {0}", myDT.ToString("y"))
Console.WriteLine(" {0} {1}", myDTFI.YearMonthPattern,
"(YearMonthPattern)")
Console.WriteLine()
Console.WriteLine(" Y {0}", myDT.ToString("Y"))
Console.WriteLine(" {0} {1}", myDTFI.YearMonthPattern,
"(YearMonthPattern)")

End Sub 'Main

End Class 'SamplesDTFI


'This code produces the following output.
'
'FORMAT en-US EXAMPLE
'CHAR VALUE OF ASSOCIATED PROPERTY, IF ANY
'
' d 1/3/2002
' M/d/yyyy (ShortDatePattern)
'
' D Thursday, January 03, 2002
' dddd, MMMM dd, yyyy (LongDatePattern)
'
' f Thursday, January 03, 2002 12:00 AM
'
' F Thursday, January 03, 2002 12:00:00 AM
' dddd, MMMM dd, yyyy h:mm:ss tt (FullDateTimePattern)
'
' g 1/3/2002 12:00 AM
'
' G 1/3/2002 12:00:00 AM
'
' m January 03
' MMMM dd (MonthDayPattern)
'
' M January 03
' MMMM dd (MonthDayPattern)
'
' r Thu, 03 Jan 2002 00:00:00 GMT
' ddd, dd MMM yyyy HH':'mm':'ss 'GMT' (RFC1123Pattern)
'
' R Thu, 03 Jan 2002 00:00:00 GMT
' ddd, dd MMM yyyy HH':'mm':'ss 'GMT' (RFC1123Pattern)
'
' s 2002-01-03T00:00:00
' yyyy'-'MM'-'dd'T'HH':'mm':'ss (SortableDateTimePattern)
'
' t 12:00 AM
' h:mm tt (ShortTimePattern)
'
' T 12:00:00 AM
' h:mm:ss tt (LongTimePattern)
'
' u 2002-01-03 00:00:00Z
' yyyy'-'MM'-'dd HH':'mm':'ss'Z'
(UniversalSortableDateTimePattern)
'
' U Thursday, January 03, 2002 8:00:00 AM
'
' y January, 2002
' MMMM, yyyy (YearMonthPattern)
'
' Y January, 2002
' MMMM, yyyy (YearMonthPattern)
'

with regards,


J.V.Ravichandran
- http://www.geocities.com/
jvravichandran
- http://www.411asp.net/func/search?
qry=Ravichandran+J.V.&cob=aspnetpro
- http://www.southasianoutlook.com
- http://www.MSDNAA.Net
- http://www.csharphelp.com
- http://www.poetry.com/Publications/
display.asp?ID=P3966388&BN=999&PN=2
- Or, just search on "J.V.Ravichandran"
at http://www.Google.com
 
Now returns a DateTime structure, not a string. You need to take care
formatting it, apparently you're relying on the default locale on the
server, which is not always the best thing to do. You have several options,
all involve creating the right locale you want your strings formatted in.
There's a good section in the .Net documentation on localization...

Jerry

Sam said:
Hi there,
This is a production issue. My application is build on .NET Frameword 1.0 form based application.
My application works fine in US.

I used the Now function to get the current system date.
I changed my computer locale to UK. My application returns current date in
US format instead of the UK format.
 
Back
Top