dddd, MMMM dd, yyyy

Gopher2011

Well-known member
Joined
Mar 3, 2011
Messages
111
Location
South England
Programming Experience
10+
Hi -I have found two threads below but they do not do exactly what I need, so I decided to post in here.

http://www.vbdotnetforums.com/vb-net-general-discussion/46944-change-format-date-day-week.html
http://www.vbdotnetforums.com/vb-net-general-discussion/3615-datetime-problems-resolved.html

I am trying to read the pc system information so that I can retrieve the time and date format.

My code below:
VB.NET:
    Dim Info As System.Globalization.DateTimeFormatInfo
    Info = System.Globalization.CultureInfo.CurrentUICulture.DateTimeFormat
    Debug.WriteLine(Info.LongDatePattern)

Retruns in debug: "dddd, MMMM dd, yyyy"

So I have 2 questions;
1) Why is there, a dd after the MMMM.

2) My company has small franchise branch offices round the world - France, USA, etc
What I am trying to do is get the date format so I can decide what country I am in - then when I print out the date on my order labels I can change the date format to suit Americans or Europeans etc.

Does anyone have advice?
 
1. Custom Date and Time Format Strings explains that.
2. When you use one of the ToString methods of the Date value, such as ToShortDateString or ToLongDateString methods, the date string is formatted automatically to culture default format. Same goes for string representations of other numeric values. Only if you want to output a different formatting than current culture you can supply a IFormatProvider argument to ToString method, such as a DateTimeFormatInfo or more commonly a CultureInfo that includes formatting information for all formats for that culture.
 
Partial fix.
Found out how to show the timezone so i can put it in a case.


In Class;

VB.NET:
     Const datF As String = "{0,-30}{1}"
     Const timF As String = "{0,-30}{1:yyyy-MM-dd HH:mm}"

In sub;

VB.NET:
      Dim localTimeZone As TimeZone = TimeZone.CurrentTimeZone


      Debug.WriteLine(dataFmt, "Standard time name:", _
            localTimeZone.StandardName)
 
There is nothing to fix, because as I said, when a date value is converted to string it is automatically formatted according to system configuration.
 
Ah ok Thanks for the relpy JohnH,

Let me add more detail.

A Siemens PLC is sending 3 text fields to the pc via a serial port. They are text1,text2,text3.

My computer program receives text1,text2,text3 as raw ascii, then prints out a sticky label.

The English put into the plc hmi DD,MM,YYYY, the Americans put MM,DD,YYYY and the Swedish put YYYY,MM,DD.
No checking whatsoever is undertaken by the Siemens PLC.

My VB program gets the 3 text stings and goes 'what the heck'... So it now needs to get the date or area locale from somewhere and print out the labels in the best region format.

Assumptions:
* assume the end user has the system timedate set correcly...



Please any advice please forward it over!!!

Thanks in advance.
 
Fixed it - This tells me the region, then i can do a string match and sort the date from here.

VB.NET:
Imports System.Globalization
...
Debug.WriteLine(System.Globalization.RegionInfo.CurrentRegion.NativeName)
[CODE]
 
You would be better to use the LCID value, as I believe this is more specific.

VB.NET:
CultureInfo.CurrentCulture.LCID
 
When you're getting the three strings that represent the DMY values you can just put those on the report without further ado, that is without first converting to date, then converting that date to string again.

If you still for some reason need to parse the strings to a Date value the Parse method will presume the locale, so if they input in the format that is the generally accepted for that region the Parse method will always pick up the correct date value. Just concat the three values with a space or DateSeparator between and it should work (you can test this with different region providers now).
 
Thanks InertiaM.
That suggestion returned 1053 - Swedish. It is more specific I agree.

So far in my testing I have used these examples below in my code:

VB.NET:
        'Regional and Langauge Options, Regional Options - Standards and Formats
        Debug.WriteLine(System.Globalization.RegionInfo.CurrentRegion.NativeName)
        Debug.WriteLine(System.Globalization.RegionInfo.CurrentRegion.ThreeLetterISORegionName)


        'Regional and Langauge Options, Regional Options - Standards and Formats (Currency)
        Debug.WriteLine(System.Globalization.RegionInfo.CurrentRegion.CurrencySymbol)
        'Regional and Langauge Options, Regional Options - Standards and Formats (Long Date)
        Debug.WriteLine(DateTimeFormatInfo.CurrentInfo.CurrentInfo.LongDatePattern)


        'Regional and Langauge Options, Advanced - Language
        Debug.WriteLine(System.Globalization.CultureInfo.CurrentUICulture)


        Debug.WriteLine(System.Globalization.CultureInfo.CurrentCulture.LCID)

But so far I can not seem to retrieve the location as shown in the image to be United Kingdom.
 

Attachments

  • Language.PNG
    Language.PNG
    33.4 KB · Views: 33
I know you need to restart your VB.Net application before language settings are displayed correctly - It seems to be stored in cashe at application startup.
Maybe the location is only ever done on system start-up and the next time the pc is started the registry is read once more.

*goes to test*
 
Last edited:
After a re-start of the PC I can confirm the following displays as below - the NativeName is not the location :(

VB.NET:
       Debug.WriteLine(System.Globalization.RegionInfo.CurrentRegion.ThreeLetterISORegionName)
       Debug.WriteLine(System.Globalization.RegionInfo.CurrentRegion.CurrencySymbol)

       Debug.WriteLine(DateTimeFormatInfo.CurrentInfo.CurrentInfo.LongDatePattern)     
       Debug.WriteLine(System.Globalization.CultureInfo.CurrentUICulture)
       Debug.WriteLine(System.Globalization.CultureInfo.CurrentCulture.LCID)

       Debug.WriteLine(System.Globalization.RegionInfo.CurrentRegion.NativeName)


DEBUG

USA
$
dddd, MMMM dd, yyyy
en-US
1033
United States

UK.PNG
 
I have fixed it from the users point of view, but form a software point of view I am still not happy.

before:
Debug.WriteLine(Format(_ExpireDate, "dd/MM/yyyy"))

********************************
28/09/2011 12:44:10
********************************


After on a US system:
Debug.WriteLine(DateTimeFormatInfo.CurrentInfo.CurrentInfo.LongDatePattern)
********************************
9/28/2011 12:44:02 PM
********************************


I still cant get the location to work but I have now stopped looking time is money. Thanks for your help JohnH / InertiaM
 
Back
Top