Come cambiare "9 novembre 03:21:11" in yymmdd mmhhss usando AppleScript / Unix?

1

Come cambiare la stringa "9 novembre 03:21:11" in yymmdd mmhhss in AppleScript?

    
posta scriptee2 09.11.2015 - 14:59
fonte

2 risposte

2

Non ho un Mac da testare, ma OSX date man page suggerisce:

old="Nov 9 03:21:11"
new=$( date -j -f "%b %e %T" "$old" "+%Y%m%d %H%M%S" )
echo "$new"

Raccomando caldamente di usare anni a 4 cifre. Non abbiamo imparato nulla da Y2K?

    
risposta data 09.11.2015 - 16:14
fonte
0

La manipolazione di data e ora in AppleScript è dolorosa. Vedi Conversione: String-Date a AppleScript-Date e Date e amp; Times in AppleScript per utili snippet e una panoramica degli approcci.

L'approccio generale sembra essere quello di assegnare al codice l'analisi e la conversione. Per il tuo esempio:

set myStringDate to "Nov 9 03:21:11"

set theMonth to first word of myStringDate
set theDayOfMonth to second word of myStringDate
set theHour to third word of myStringDate
set theMinute to fourth word of myStringDate
set theSecond to fifth word of myStringDate

-- TODO: Add code to convert month to a number
set theConvertedMonth to theMonth

-- Determine the year somehow

set myTransformedDate to "YEAR" & theConvertedMonth & theDayOfMonth & " " & theMinute & theHour & theSecond

-- Be aware of numbers of single digits; you may need to pad with zeros

Se ti senti a tuo agio con la riga di comando, potresti trovare più facile ricorrere alla chiamata a uno script di shell per la conversione.

    
risposta data 09.11.2015 - 15:05
fonte

Leggi altre domande sui tag