Re: Localized dates and times
Re: Localized dates and times
- Subject: Re: Localized dates and times
- From: Marc Laffitte <email@hidden>
- Date: Tue, 13 Nov 2001 11:42:11 +0100
- Resent-date: Tue, 13 Nov 2001 11:46:09 +0100
- Resent-from: Marc Laffitte <email@hidden>
- Resent-message-id: <email@hidden>
- Resent-to: email@hidden
Thanks!
This works fine. Somehow I did not see the NSUserDefaults class until
now ;)
This put on the way to the result, but this is not enough...
If I do the following:
NSString * tFormatString = [[NSUserDefaults standardUserDefaults]
objectForKey:NSDateFormatString];
NSString * tDateString = [NSCalendarDate
descriptionWithCalendarFormat:tFormatString];
I get something like:
Thursday 15 November 2001
Let me say that in the International panel of my System Preferences, I
have English as the main language, and French for Date, Time and Numbers.
If I use NSTimeDateFormatString instead of NSDateFormatString, I get:
Thursday, November 15, 2001 18:00:12
The funny thing is that if I do directly:
[IBDateTimeField_ setObjectValue:[NSDate
dateWithTimeIntervalSince1970:tMyDateSince1970]];
I get something like:
mardi, novembre 12, 2001 18:00:53
All of this does not look very consistent... My system clock in the menu
bar displays also words in french with an english formating.
The solution is not only to pass the format to the NSCalendarDate object
but also the [NSUserDefaults standardUserDefaults] dictionary (passing
only the dictionary is also not enough):
NSString * tDateString = [NSCalendarDate
descriptionWithCalendarFormat:tFormatString locale:[NSUserDefaults
standardUserDefaults]];
However, if I want to display date _and_ time, I cannot rely on
NSTimeDateFormatString which obviously returns allways an english format
string. I had to build a custom format string with the results of
NSDateFormatString and NSTimeFormatString...
----------------------
En rappel, la devise des Shadoks: "Pourquoi faire simple quand on peut
faire compliqui ?" ;-)
With other words: "Why do things simple if you can do them complicated ?"
On lundi, novembre 12, 2001, at 08:19 , Chris Parker wrote:
Marc,
With a locale set as you have it, you should be able to ask
NSUserDefaults for NSDateFormatString which will tell you what the
formatter is for that locale.
NSString *dateFormat = [[NSUserDefaults standardUserDefaults]
objectForKey:NSDateFormatString];
This worked for me with a "Language" setting of English and a "Date"
setting of French. It returns
%A %e %B %Y
with the default French settings
.chris
On Monday, November 12, 2001, at 10:55 AM, Marc Laffitte wrote:
I lost enough time searching for an answer, so let me ask you:
What I want to do should be relatively easy:
I just want to display an NSDate (or NSCalendarDate) in a text field
according to the user Date and Time settings in the International pane
of the system preferences.
So, even if the main system language is set to English, if I use
French for date and time, I would like something like: lundi 12
novembre 2001, 19h43
What I get for now is "lundi, novembre 12, 2001 18:00:53" if I do
somethiing like:
NSString * tDateString = [NSDate
dateWithTimeIntervalSince1970:myDateSince1970];
If instead of an NSDate I use an NSCalendarDate, I can set the format
to what I want but I don't know how to get the currents settings. (I
could read directly the pref file
/Users/<currentUser>/Library/Preferences/com.apple.HIToolbox.plist,
but I don't think this would be very clean).
However, with such a format, I get the day and months in english, not
french as set in my system preferneces...
If I connect my text field with an NSDateFormatter in my nib file,
days and months are displayed in the right language. But the format is
fixed to whatever is defined in the nib file. Even if I can choose an
other NSDateFormater, I still don't know how to get the current user
settings.
I suppose I am missing something probably trivial, but...
I would appreciate any help.
Marc
PS: My system clock has also some difficulties in displaying dates the
correct way: It shows "lundi 11/12/2001 7:51" instead of "lundi
12/11/2001 19:51" according to my settings...
_______________________________________________
cocoa-dev mailing list
email@hidden
http://www.lists.apple.com/mailman/listinfo/cocoa-dev