ToShortDateString missing two first digits in the year

  • Thread starter Thread starter Peter Hartlén
  • Start date Start date
P

Peter Hartlén

Hi!

I've converted a project from CF1 to CF2 (PocketPC 2003 SE) and all the
sudden the DateTime.ToShortDateString() returns a date of the format
yy-mm-dd instead of yyyy-mm-dd as it did for CF1 (I'm using swedish locale).

I.e. instead of 2006-10-24 I get 06-10-24

On the full framework I still get 2006-10-24, so what's up?

/ Peter
 
Peter,

give DateTime.ToString("yyyy-MM-dd") instead of ShortDateString a try.

HTH
Ruediger
 
Well that works as long as I am using the current locale, but if I switch to
en-US locale it should be dd-MM-yyyy right? What I mean to say is that I
don't want to force the date into a specific format as it depends on the
locale...

/ Peter
 
ToShortDateString returns whatever format is set in devices regional
settings for short date.

On a full framework you're also getting whatever format is set in regional
setting which user can change to use 2 digits for year.

So you can either change your code to work with any possible format set by
user or use particular format as Peter suggested.



Now, why it worked on NETCF V1? That is because it mostly ignored regional
settings.


--
Best regards,


Ilya

This posting is provided "AS IS" with no warranties, and confers no rights.

*** Want to find answers instantly? Here's how... ***

1. Go to
http://groups-beta.google.com/group/microsoft.public.dotnet.framework.compactframework?hl=en
2. Type your question in the text box near "Search this group" button.
3. Hit "Search this group" button.
4. Read answer(s).
 
Peter,

as Ilya explained: DateFormat depends on the user settings.

if yout want to force the format to use "yyyy" use

System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.ShortDatePattern.ToString()

to get the current format.
Check for "yy" or "yyyy" (same with "M"/"MM" and "d"/"dd") an construct the
format you're happy with.

HTH
Ruediger
 
Ah....

I can see now that the date in Regional Settings in WM2003 actually states
that the short format is yy-MM-dd.

How come it doesn't use the same format as on e.g. Windows XP?

Anyway, thanks for the explanation!

/ Peter
 
Back
Top