• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: System Date Format
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: System Date Format


  • Subject: Re: System Date Format
  • From: Paul Berkowitz <email@hidden>
  • Date: Thu, 04 Sep 2003 01:32:53 -0700

On 9/4/03 12:37 AM, "John Baltutis" <email@hidden> wrote:

>> Not quite right... Maybe there's some strftime switch I can find to
>> substitute for "1m". Nope, it must be a "special" adaptation. Well, I can do
>> some AppleScript stuff now that I know what it means (remove the leading
>> zero, and the leading blank for %e). I'll need to try out several date
>> formats in System Prefs.
>>
>
> Note that you'll have the same problem with the time format: I get
> "%1I:%M:%S" when it's set for a 12-hour US clock. Let us know if you figure
> out the substituitons for 1m and the 1l.

Actually, in this case, I need it for an AppleScript Studio application. The
Cocoa methods I'm calling understand understand this "Apple-special"
terminology - where "1" interpolated in a Unix % code means "no leading
zeroes, 1 digit only if < 10) - it turns out. It also does not insert a
blank space for "%e" - 1 digit only there too. I was sort of hoping that was
the case when I saw the NSDateFormatString term - that's a Cocoa class.

If I were doing regular AppleScript I'd do something like


set dateFormat to do shell script "defaults read -g NSShortDateFormatString"
set AppleScript's text item delimiters to {"1"}
set segments to text items of dateFormat
set AppleScript's text item delimiters to {""}
set uDateFormat to segments as string
set separator to character 2 of item 2 of segments
set AppleScript's text item delimiters to {separator}
set segments to text items of dateFormat
set removeZeroes to {}
repeat with i from 1 to (count segments)
set aSegment to item i of segments
if aSegment contains {"1"} then set end of removeZeroes to i
end repeat

set shortDate to do shell script "date +" & uDateFormat
set segments to text items of shortDate
repeat with i from 1 to count segments
set aSegment to item i of segments
if ({i} is in removeZeroes and aSegment starts with "0") or (aSegment
starts with " ") then
set item i of segments to text 2 thru -1 of aSegment
end if
end repeat
set shortDate to segments as string
set AppleScript's text item delimiters to {""}
shortDate
--> 9/4/03


--------
Using

do shell script "defaults read -g NSTimeFormatString"

for the first line, I get:

--> "1:16:56"

(I'm surprised the time default doesn't include " %p" at the end for AM/PM)



It sure is a lot easier in Cocoa/Studio.



--
Paul Berkowitz
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.

  • Prev by Date: Re: Weird Finder bug - or not?
  • Next by Date: Displaying a lists items as items
  • Previous by thread: Re: System Date Format
  • Next by thread: How to open Package folder?
  • Index(es):
    • Date
    • Thread