How to get user's local date format

G

Guest

User can changes his/her local date setting, i.e., "M/d/yyyy", "dd/MMM/yyyy", .... etc. which interprets the date (string type) in the different way. for example "02/05/2004" can be the second of May or the fifth of Februry. So, it's neccessary to get the local date setting before display this date.

Any body knows
1. How to get the user's local date format o
2. How to enforce to use a standard date format for display the dat

Thread.CurrentThread.CurrentCulture = New CultureInfo("en-US"
can enforce to use a region but can't get a specific date format define by users
 
G

Guest

I found these codes

Private Declare Function GetSystemDefaultLCID Lib "kernel32" () As Intege
Private Const LOCALE_SSHORTDATE As Short = &H1Fs ' short date format strin
Private Declare Function GetLocaleInfo Lib "kernel32" Alias "GetLocaleInfoA"(ByVal Locale As Integer, ByVal LCType As Integer, ByVal lpLCData As String, ByVal cchData As Integer) As Intege

Public Sub Main(

Dim sReturn As Strin
Dim r As Intege
Dim LCID As Intege
LCID = GetSystemDefaultLCID(
r = GetLocaleInfo(LCID, LOCALE_SSHORTDATE, sReturn, Len(sReturn)

If r The
sReturn = Space(r
r = GetLocaleInfo(LCID, LOCALE_SSHORTDATE, sReturn, Len(sReturn)
MsgBox(Left(sReturn, r - 1)
End I
End Sub
 
A

Armin Zingler

Li Pang said:
User can changes his/her local date setting, i.e., "M/d/yyyy",
"dd/MMM/yyyy", .... etc. which interprets the date (string type) in
the different way. for example "02/05/2004" can be the second of May
or the fifth of Februry. So, it's neccessary to get the local date
setting before display this date.

Any body knows
1. How to get the user's local date format or
2. How to enforce to use a standard date format for display the
date

Thread.CurrentThread.CurrentCulture = New CultureInfo("en-US")
can enforce to use a region but can't get a specific date format
define by users.

I'm not sure what's your intention. To convert from String to DateTime, you
can use DateTime.Parse, and optionally pass a Cultureinfo object to use
settings different from the current culture. Same for the other way, i.e.
DateTime.ToString.


--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top