473,508 Members | 2,247 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to gather the ture short date format?

ABC
I set the date format as "MM/dd/yyyy" on control panel. Then, I use
System.Globalization.DateTimeFormatInfo.CurrentInf o.ShortDatePattern to
return short date format. But it has not return my expected format, which
return 'M/d/yyyy'. How should I do?
Nov 17 '05 #1
6 3572
Use "d".

- Peter Gummer
Nov 17 '05 #2
ABC
what? "d"???

I only want to gather the date format string like as "MM/dd/yyyy".


"Peter Gummer" <pe******************@hotnospammail.com> wrote in message
news:OL**************@TK2MSFTNGP10.phx.gbl...
Use "d".

- Peter Gummer

Nov 17 '05 #3
ABC wrote:
what? "d"???

I only want to gather the date format string like as "MM/dd/yyyy".


That's exactly what "d" does, according to the on-line help. Try it!

-- Peter Gummer
Nov 17 '05 #4
Unless CultureInfo.UseUserOverride is true, settings in Control Panel
will not be used by the CultureInfo class. However, this property can
only be set at construction time, so you may need to create a new
instance of CultureInfo instead of using CultureInfo.CurrentCulture:

CultureInfo info = new CultureInfo(CultureInfo.CurrentCulture.LCID,
true);
string shortDateFormat = info.DateTimeFormat.ShortDatePattern;

---------------
Thi - http://thith.blogspot.com

Nov 17 '05 #5
ABC
I tried this test, but it returns not my expected.

I found this line can return my result. Pls use it.
System.Globalization.DateTimeFormatInfo.InvariantI nfo.ShortDatePattern;

"Truong Hong Thi" <th*****@gmail.com> wrote in message
news:11*********************@g47g2000cwa.googlegro ups.com...
Unless CultureInfo.UseUserOverride is true, settings in Control Panel
will not be used by the CultureInfo class. However, this property can
only be set at construction time, so you may need to create a new
instance of CultureInfo instead of using CultureInfo.CurrentCulture:

CultureInfo info = new CultureInfo(CultureInfo.CurrentCulture.LCID,
true);
string shortDateFormat = info.DateTimeFormat.ShortDatePattern;

---------------
Thi - http://thith.blogspot.com

Nov 17 '05 #6
Hi ABC, you said that you wanted to retrieve the short date pattern
that you specified in Control Panel, right? As far as I know, the
invariant info always returns the same thing whatever culture and
settings are. I think it returned what you expected was just a
coincidence. Have you tried changing things in Control Panel and run it
again?

I think the Current info would work. I suspect that you have changed it
prevously somewhere in your application. To test this, you might write
a simple console program which writes current culture info on screen.

If you have changed the app current culture, and then want to get the
user's regional settings in Control Panel, you should backed up the
current culture before changing it. A alternative is using my code
above, but instead of CultureInfo.CurrentCulture.LCID, you might want
to get the LCID by using Windows API GetUserDefaultLCID function.

Regards,
Thi - http://thith.blogspot.com

Nov 17 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
4829
by: Laurence Neville | last post by:
This is regarding a change in the Short Date format under Hebrew Regional Settings, that has caused huge problems in our ASP web application. The change appears to have been introduced sometime...
4
19789
by: Jo | last post by:
Is there anyway we can know using JavaScript the Short Date Format used in the Control Panel -> Regional and Language Settings? I know the using the combinations of following we can get the...
0
2084
by: Galina | last post by:
Hello My form is based on a query returning rows of a table. Practically, it is based on a table, so simple the query is. A field on the form is formatted as short time. The column in the table,...
1
2499
by: kgatchell2001 | last post by:
Hi, I am a beginner working on a database to manage clients, payroll, station assignments, etc. I have created a query which calculates age based on subtracting the date of birth from the current...
7
8449
by: Edward Mitchell | last post by:
I have a number of DateTimePicker controls, some set to dates, some set to a format of Time. The controls are all embedded in dialogs. I created the controls by dragging the DateTime picker from...
3
1961
by: MattB | last post by:
I've hit a snag with an application I wrote because of the differing date formats in different countries. It's a set of pages that make calls to a COM object that I have wrapped in a web...
6
2358
by: ABC | last post by:
Is there any function return the short date format on the regional and Language Options under control panel?
2
6992
by: savigliano | last post by:
hello, i am doing a date comparation and i have reallize that the data i have in my database (general date format) it is causing me problems, and because i don´t need the time data i would like to...
3
2218
by: Matt Brown - identify | last post by:
Hello, I'm trying to figure out a method to look up by a range of dates, entries in a database. The format of the date in the database is "M\D \yyyy HH:MM:SS". What i need to do is take the...
0
7231
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7132
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7336
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7063
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
4720
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3196
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1568
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
773
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
432
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.