将日期从字符串转换为 JMP 日期:AM/PM 与 24 小时时间问题考虑以下场景:
MyDateStr = "2/19/2018 10:04:28 PM";
信息(MyDateStr,“月/日/年:分:秒”);
这会在 JMP 日志中返回正确的日期/时间值 ( 19Feb2018:22:04:28 ),只要我电脑上的日期/时间格式设置为 hh:mm:ss tt (即12小时时间)
如果我将计算机上的格式设置为 24 小时时间 ( HH:mm:ss ) 并且运行上述代码,JMP 会给出缺失值。 它无法正确解释日期。 如果我把“PM”从末尾去掉,它就会起作用。
在设置为 24 小时时间的计算机上运行时,如何让 JMP 正确解析以 12 小时时间指定的日期/时间字符串?
回复:将日期从字符串转换为 JMP 日期:AM/PM 与 24 小时时间问题我得出的结论是,这不能在 1 个班轮中完成:
<< use Locale(0) 对我的计算机没有影响,它仍然不会解释包含 AM/PM 的时间戳,除非计算机设置为 12 小时时间。
我发现了类似的讨论这里。
我的结论是我可以可靠地做到这一点的唯一方法是这样的:
上午下午=子字符串(时间戳字符串,- 2 , 2 ) ;
时间戳字符串=代替(时间戳字符串, “ 是” , ”” , “下午” , ”” ) ;
匹配(上午下午,
“是” ,尝试( :时间戳=提供信息(时间戳字符串, “月/日/年:月:秒” )) ;
,
“下午” ,尝试( :时间戳=提供信息(时间戳字符串, “月/日/年:月:秒” ) +几小时内( 12 ))
) ;
这是一大堆代码来完成一些相当琐碎的事情,但它确实有效
回复:将日期从字符串转换为 JMP 日期:AM/PM 与 24 小时时间问题你好,
这是“万福玛丽”类型的回复。 如果您只使用 Informat( MyDateStr ) 或等效方法,您会得到什么,
解析日期(MyDateStr)。
另外,书中使用 JMP章节列信息窗口它指出“区域设置日期因本地操作系统设置而异。”还有JSL 语法参考节目
格式( x, "货币", "欧元", 20, <<使用区域设置(0)); // 忽略计算机区域设置
InFormat() 和 Parse Date() 显示第三个参数 <
所以我的“万福玛丽”建议是:
- 单独使用 Informat( MyDateStr )
- use Informat( MyDateStr, "m/d/yh:m:s", << 使用 Locale(0) );
- 从字符串创建一列
看剧本。它显示了 Informat() 的强大功能,甚至可以正确转换 30/12/.... 但就地转换(至少我们以前的方法)不再有效。我希望你能找到有用的东西。
//------#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" );
回复:将日期从字符串转换为 JMP 日期:AM/PM 与 24 小时时间问题甚至
<< Use Locale(0)
对我来说有用。我在文档中找不到这个。天哪,日期/时间转换太难了!