帶時間的 Informat (ParseDate) 函數你好,
我對 Informat 函數(或其別名 ParseDate)有疑問。 如果我有一個包含日期和時間信息的字符串,我會嘗試在 JMP 15.2.0 上解析日期。
str="2022-10-22 16:25:37";
datetime= Informat( str, "yyyy-mm-dd HH:mm:ss" );
show(type(datetime));
show(datetime);
根據日期時間設置 (Win 10),我得到不同類型的輸出。
區域格式英語(英國):
str = "2022-10-22 16:23:37";
類型(日期時間)=“日期”;
日期時間 = 22Oct2022:16:23:37;
或區域格式芬蘭語(芬蘭):
str = "2022-10-22 16:23:37";
類型(日期時間)=“數字”;
日期時間 = .;
有沒有可以解析時間的函數? 或者有建議如何做到這一點?
腳本視窗回复:帶時間的 Informat (ParseDate) 函數謝謝,此示例適用於測試的日期時間設置。
回复:帶時間的 Informat (ParseDate) 函數我用過<< 使用 Locale() 解決日期和時間格式問題。 您提供的示例沒有解決問題,我想我稍後有時間再回來討論這個問題(雙關語)。 該示例的問題很可能已通過 << Use Locale() 解決。如果我得到更新版本的 JMP,我也會嘗試格式模式。
再次感謝分享您的知識。
回复:帶時間的 Informat (ParseDate) 函數這是處理此問題的一種方法
str="2022-10-22 16:25:37";
datetime = datemdy(num(word(2,str," -:")),
num(word(3,str," -:")),
num(word(1,str," -:")) ) +
3600*num(word(4,str," -:")) +
60 * num(word(5,str," -:")) +
num(word(6,str," -:")
);
show(format(datetime,"m/d/y h:m:s"));
它顯示在日誌中
Format(datetime, "m/d/y h:m:s") = "10/22/2022 4:25:37 PM";
回复:帶時間的 Informat (ParseDate) 函數檢查使用 << Use Locale() 是否有幫助。
在 JMP16 之前,JMP 在管理時間(和日期)方面相當糟糕。 我很可能會將字符串解析為年、月、日、小時、分鐘和秒。 然後將它們相加得到 date_time。 使用 JMP16,您很可能只使用 Format Pattern
也許這可以提供一些想法:
Names Default To Here(1);
str = "2022-10-22 16:25:37";
date = Word(1, str, " ");
time = Word(2, str, " ");
y = Num(Word(1, date, "-"));
m = Num(Word(2, date, "-"));
d = Num(Word(3, date, "-"));
time_separator = Left(Regex(Format(Today(), "h:m:s"), "\d", "", GLOBALREPLACE), 1);
hh = Num(Word(1, time, time_separator));
mm = Num(Word(2, time, time_separator));
ss = Num(Word(3, time, time_separator));
date_time = Date DMY(d, m, y) + hh * 60 * 60 + mm * 60 + ss;
AsDate(date_time);
回覆:Informat (ParseDate) 函數與時間似乎在 Jmp 15.2 Informat 中只是忽略了像這樣的奇特模式
datetime= Informat( str, "yyyy-mm-dd HH:mm:ss" );
即使pattern =“hello”也會導致

在以後的版本中,Jmp會告訴使用者:
未知格式:你好
什麼有效:
使用格式模式選項提供資訊:
<HH><:><MM> <:><SS> “ ); 顯示(類型(日期時間)); 顯示(日期時間);</SS></MM></HH>str="2022-10-22 16:25:37";
datetime= Informat( str, "Format Pattern", "<YYYY><MM></MM></YYYY>