I can’t test your script immediately without changing my date/time settings. But do you get the same results if you use AppleScript’s current, Unicode-compatible terminology?
set my_date_time to (current date) as text
set theNonSpaceCharacter to character -3 of my_date_time
set theChar to character id (id of theNonSpaceCharacter)
Apple is using a narrow no-break space between the seconds and the ante/post meridiem (am/pm) characters. The UTF-8 code for a narrow no-break space is E2 80 AF.
One can replace that offending space character in an AppleScript date string by the following code:
-- replace the UTF-8 narrow no-break space with a simple space
set adate to (current date) as text
set fixedDate to do shell script "sed 's/\\xe2\\x80\\xaf/\\x20/g' <<<" & adate's quoted form
Here is an ASObjC solution (using the narrow no-break space’s decimal Unicode code point value 8239) if one wishes to avoid the overhead of the do shell script command:
use framework "Foundation"
use scripting additions
set my_date_time to (current date) as text
set cleaned_date_time to ((current application's NSString's stringWithString:my_date_time)'s stringByReplacingOccurrencesOfString:(character id 8239) withString:space) as text
or a somewhat wordier Vanilla AppleScript solution:
set my_date_time to (current date) as text
set {tid, AppleScript's text item delimiters} to {AppleScript's text item delimiters, character id 8239}
tell my_date_time's text items
set AppleScript's text item delimiters to space
set {cleaned_date_time, AppleScript's text item delimiters} to {it as text, tid}
end tell
or a more terse Vanilla AppleScript solution if one is certain that there is only a single narrow no-break space and that it is at neither the beginning nor the end of the string:
set my_date_time to (current date) as text
set ox to offset of character id 8239 in my_date_time
tell my_date_time to set cleaned_date_time to text 1 thru (ox - 1) & space & text (ox + 1) thru -1