convertire una data da una stringa in una data JMP: AM/PM vs problemi di tempo di 24 oreConsidera il seguente scenario:
MyDateStr = "19/02/2018 22:04:28";
informat(MyDateStr, "m/g/aa:m:s");
Ciò restituisce un valore di data/ora corretto ( 19Feb2018:22:04:28 ) nel registro JMP, purché il formato data/ora sul mio computer sia impostato su hh:mm:ss tt (vale a dire 12 ore di tempo)
Se ho il formato sul mio computer impostato su 24 ore ( HH:mm:ss ) ed eseguo il codice sopra, JMP mi dà un valore mancante. Non riesce a interpretare correttamente la data. Se lascio cadere il "PM" alla fine funzionerà.
Come faccio a fare in modo che JMP analizzi correttamente le stringhe di data/ora specificate in 12 ore durante l'esecuzione su un computer impostato su 24 ore?
Oggetto: conversione di una data da una stringa in una data JMP: problemi di orario AM/PM vs 24 oreHo concluso che non può essere fatto in un 1 liner:
<< use Locale(0) non ha alcun effetto sulla mia macchina, non interpreterà ancora un timestamp che include AM/PM a meno che il computer non sia impostato su 12 ore.
c'è una discussione simile che ho trovato Qui .
La mia conclusione è stata che l'unico modo in cui posso farlo in modo affidabile è così:
AM PM = sost ( TimeStampStr ,- 2 , 2 ) ;
TimeStampStr = sostituire ( TimeStampStr , " SONO" , "" , "PM" , "" ) ;
Incontro ( AM PM ,
"SONO" , Tentativo ( : Timestamp = informat ( TimeStampStr , "m/g/aa:m:s" )) ;
,
"PM" , Tentativo ( : Timestamp = informat ( TimeStampStr , "m/g/aa:m:s" ) + In ore ( 12 ))
) ;
Che è un sacco di codice per fare qualcosa di piuttosto banale ma funziona
Oggetto: conversione di una data da una stringa in una data JMP: problemi di orario AM/PM vs 24 oreCIAO,
Questo è un tipo di risposta "Ave Maria". Cosa ottieni se usi semplicemente Informat( MyDateStr ) o equivalentemente,
Analizza data( MyDateStr ).
Inoltre, nel libro Utilizzo di JMP capitolo La finestra delle informazioni sulla colonna afferma che "la data locale varia in base all'impostazione del sistema operativo locale".E il Riferimento alla sintassi JSL Spettacoli
Format( x, "Currency", "EUR", 20, <
InFormat() e Parse Date() mostrano un terzo argomento <
Quindi i miei "suggerimenti per l'Ave Maria sono:
- usa Informat( MyDateStr ) da solo
- use Informat( MyDateStr, "m/d/yh:m:s", << Use Locale(0) );
- creare una colonna dalla stringa
Guarda la sceneggiatura.Mostra la potenza di Informat() anche convertendo correttamente 30/12/.... Ma la conversione in atto (almeno i nostri metodi precedenti) non funzionava più.Spero che tu trovi qualcosa che funzioni.
//------#6: Create a data table with a Character column of different date time formats
dtimeList={};
InsertInto( dtimeList, "JUN162010 2:59:13");
InsertInto( dtimeList, Format(AsDate(Today()), "yyyy-mm-ddThh:mm:ss"));
InsertInto( dtimeList,Format(AsDate(Today() - 3*34*60), "yyyy-mm-ddThh:mm"));
InsertInto( dtimeList,Format(AsDate(Today() + 12*34*60), "yyyy-mm-ddThh:mm"));
InsertInto( dtimeList, "12/01/2010");
InsertInto( dtimeList, "01/12/2010");
InsertInto( dtimeList, "30/12/2010 1:1:1");
test3_dt = New Table ("Test Datetime", new Column("dummy", character));
test3_dt << add rows( nitems(dtimelist));
test3_dt:dummy << set values (dtimeList);
//----run to here---------------------------------------------------------
//----Look at the data table...create a new column using Parse Date function
convCol = test3_dt << New Column( "Parsed dummy", Numeric, Continuous );
convCol << set each value (Informat(:dummy) );
convCol << Format("monddyyyy h:m:s");
wait(2);
convCol << Format("m/d/y h:m:s");
//---The code below worked in JMP 8 and 9 and 10 and maybe 11. It does not work in JMP 12, 13, 14
//Also, even though the column has mixed formats, by converting to numeric,
//continuous and specifying a datetime format, JMP automatically parses the dates
//:dummy << {data type( "Numeric"), Modeling Type("Continuous") };
//:dummy << Format("m/d/y h:m:s" );
Re: conversione di una data da una stringa in una data JMP: problemi di tempo AM/PM vs 24 oreAnche il
<< Use Locale(0)
ha funzionato per me. Non l'ho trovato da nessuna parte nella documentazione. Cavolo, le conversioni data/ora sono così difficili!