Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hi,

In my application I want to make sure that all dateformats are like "2004-06-11" no matter what the user has set in his regional settings.

 

I thought it would be easy just....

Application.CurrentCulture.DateTimeFormat.ShortDatePattern = "yyyy-MM-dd"

but oh, no! This property is read-only.

And creating a new one

Dim ciMe As System.Globalization.CultureInfo = System.Globalization.CultureInfo.InvariantCulture()

ciMe.DateTimeFormat = New System.Globalization.DateTimeFormatInfo()
ciMe.DateTimeFormat.ShortDatePattern = "yyyy-MM-dd"

won't work either.

 

Please help me out.

/Kejpa

  • *Experts*
Posted (edited)

I had to do a similar thing with the decimal seperator. As an example, here's my solution, also the only way I found this to work.

InformationBox() is a custom dialog MessageBox.

   Private Sub Check_DecimalSeparator()

       Dim separatorFormat As New System.Globalization.NumberFormatInfo()
       If separatorFormat.CurrentInfo.NumberDecimalSeparator = "," Then
           Dim frmInformationBox As New InformationBox()
           frmInformationBox.Captions("Comma Decimal Seperator Format", "Volts currently supports and displays a dot(.) as a decimal separator.", "Information", "Okay")
           frmInformationBox.ShowDialog()

           Thread.CurrentThread.CurrentCulture = New CultureInfo("en-US")
           separatorFormat.NumberDecimalSeparator = "."
       End If
   End Sub

 

This snippet shows how to check and override the users Regional settings. You will need to check Window's Regional settings to get the date format you want. Also, changing the format as I did is only temporary and will not affect the users settings once your program is exited.

 

I also had to set date formats in Volts, but chose to do it as a user defined setting...

One for the USA standard.

One for the rest of the World's standard.

And one for military standard - always gotta be different here, sorta like "there's always one in every crowd" different!

 

Now for the commentary ...

Why does the USA have to have the decimal seperator and date format completely different from the rest of the World? It makes a lot of sense to use a comma instead of a dot for a decimal seperator as most of the SI world has currently adapted. The date format is so trival that I wish that someone will adapt one of the two formats as standard (forget the military, they won't listen to anything that makes common sense anyway). Then multi-national programmers could spend their time doing stuff that's really important compared to silly date and decimal seperator formats.

End of commentary ... :rolleyes:

 

Dan

Edited by DiverDan

Member, in good standing, of the elite fraternity of mentally challenged programmers.

 

Dolphins Software

  • *Experts*
Posted

I love it! Brilliant!

All kinding aside, math, date formats included, should be universal with set standards. Even the USA has adapted SI units in science and engineering. Metrics are soon to follow. Everyone is an individual and should express themselves as individuals, but this stuff is math, science and engineering.

 

Dan

Member, in good standing, of the elite fraternity of mentally challenged programmers.

 

Dolphins Software

Posted

Thanx Diverdan,

I've gotten it to work,

 

and for your comment on standards ....

"Standards are great, everyone should have his."

 

SeaU

/Kejpa

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...