Re: Date Format Conversion
Re: Date Format Conversion
- Subject: Re: Date Format Conversion
- From: Brian Stern <email@hidden>
- Date: Thu, 22 Jun 2006 12:40:31 -0400
At 1:11 PM -0300 6/22/06, Neto wrote:
>
>Anyway...just thoughts, because I don't know how to implement the
>"checkCurrentSystemDateFormat" or the "checkFirstTwoCharacters" methods.
Use NSScanner for checkFirstTwoCharacters.
http://developer.apple.com/documentation/Cocoa/Conceptual/Strings/Articles/Scanners.html
This code has worked for me to determine the system date format:
static BOOL sDayBeforeMonth; // Date format is dmy or mdy
// =======================================================================
// determineDateFormat
// =======================================================================
// Gets the user setting for date formatting, either MDY or DMY
// Also look at NSShortDateFormatString or NSDateFormatString
// NSDateTimeOrdering doesn't work. It's apparently MDYH on all computers.
// NSShortDateFormatString is %1m/%e/%y on a US machine. Can be displayed with
// defaults read NSGlobalDomain NSShortDateFormatString
- (void)determineDateFormat
{
NSString* f = [[NSUserDefaults standardUserDefaults]
objectForKey:NSShortDateFormatString];
// NSLog(@"%@ %@", f, NSShortDateFormatString);
NSRange rMonth, rDay;
rMonth = [f rangeOfString:@"m"];
if (rMonth.length == 0)
rMonth = [f rangeOfString:@"b"];// not sure if this can happen
if (rMonth.length == 0)
rMonth = [f rangeOfString:@"B"];// not sure if this can happen
rDay = [f rangeOfString:@"e"];
if (rDay.length == 0)
rDay = [f rangeOfString:@"d"]; // not sure if this can happen
// Is it US format or EUR format?
// MDYH or DMYH @"%m/%d/%Y" or @"%d/%m/%Y"
// The default in the nib is EUR format
// Change to US format if we need to
if (rMonth.location < rDay.location) // User is US format
{
sDayBeforeMonth = NO; // US format
}
else
{
sDayBeforeMonth = YES; // EUR format
}
// NSLog(@"sDayBeforeMonth: %@", sDayBeforeMonth ? @"YES":@"NO");
}
// Return whether the user's date format is dmy, which is european style.
// returns false if user's date format is mdy, american style.
+ (BOOL)dateFormatIsDayBeforeMonth
{
return sDayBeforeMonth;
}
--
Brian Stern
email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden