让我们从这篇文章的目的开始:
当用户具有不同的区域设置时,您是否遇到过日期和时间方面的问题?您是如何处理这些问题的?
在编写脚本和共享这些脚本时,我不时遇到不同时间格式(和日期)的问题(最近一直在与具有不同语言环境和 JMP 设置的用户合作)。 此问题通常与时间格式有关,因为 JMP 不提供时间的“通用”格式(对于日期,我可以使用区域设置日期)。
在 JMP16 之前,我已经编写了自己的代码来检查用户是否使用 : 或 .作为时间分隔符,然后基于它构建 Locale Date Time 格式:
timeSeparator = Left(Regex(Format(Today() ,"h:m:s"), "\d", "", GLOBALREPLACE),1);
customFormat = "Locale Date Time h"||timeSeparator||"m"||timeSeparator||"s";
JMP16 通过 Format Pattern 帮助解决此问题,但在进行格式化时使用它并不是最简单的(用户必须知道使用 <::> 作为时间分隔符):
<-><MM><-><YYYY> <HH24><::><MM><::><SS>", << Set Wrap(500)),
cal1 = Number Edit Box(Today()),
Text Box("Locale Date Time h:m:s", << Set Wrap(500)),
cal2 = Number Edit Box(Today()),
Text Box("Locale Date Time h.m.s", << Set Wrap(500)),
cal3 = Number Edit Box(Today()),
Text Box("yyyy-mm-ddThh:mm:ss", << Set Wrap(500)), //ISO format?
cal4 = Number Edit Box(Today()),
Text Box("Built locale date format", << Set Wrap(500)),
cal5 = Number Edit Box(Today()),
Text Box("No format", << Set Wrap(500)),
cal6 = Number Edit Box(Today())
));
cal1 << Set Format(Format("Format Pattern", "</SS></MM></HH24></YYYY></MM><-><-> <::><::>"));
cal2 << Set Format(Format("Locale Date Time h:m:s"));
cal3 << Set Format(Format("Locale Date Time h.m.s"));
cal4 << Set Format(Format("yyyy-mm-ddThh:mm:ss"));
timeSeparator = Left(Regex(Format(Today() ,"h:m:s"), "\d", "", GLOBALREPLACE),1);
customFormat = "Locale Date Time h"||timeSeparator||"m"||timeSeparator||"s";
cal5 << Set Format(customFormat);
Print("Show");
Show(Format(Today(),"Format Pattern", "<-><-> <::><::>"));
Show(Format(Today(),"Locale Date Time h:m:s"));
Show(Format(Today()(),"Locale Date Time h.m.s"));
Show(Format(Today(),"yyyy-mm-ddThh:mm:ss"));
Show(Format(Today(),customFormat));
Show(Today());
Print("Data table");
dt = New Table("Untitled",
Add Rows(1),
Compress File When Saved(1),
New Column("FormatPattern", Numeric, "Continuous", Format("Best", 12), << Set Each Value(Today())),
New Column("LocaleDateTime:", Numeric, "Continuous", Format("Best", 12), << Set Each Value(Today())),
New Column("LocaleDateTime.", Numeric, "Continuous", Format("Best", 12), << Set Each Value(Today())),
New Column("ISO?", Numeric, "Continuous", Format("Best", 12), << Set Each Value(Today())),
New Column("Custom", Numeric, "Continuous", Format("Best", 12), << Set Each Value(Today())),
New Column("NoFormat", Numeric, "Continuous", Format("Best", 12), << Set Each Value(Today()))
);
Column(dt, "FormatPattern") << Format("Format Pattern", "<-><-> <::><::>");
Column(dt, "LocaleDateTime:") << Format("Locale Date Time h:m:s");
Column(dt, "LocaleDateTime.") << Format("Locale Date Time h.m.s");
Column(dt, "ISO?") << Format("yyyy-mm-ddThh:mm:ss");
Column(dt, "Custom") << Format(customFormat);
Show(Today());Format("Format Pattern", "<YYYY><-><MM><-><DL><DD> <HH24><::><MM><::><SS>");<P> </P><P>根据我在做什么,我有不同的解决方案,如果我只想在文本框中输入日期和时间,我通常只使用 AsDate(),但是当我想构建特定报告或提供带有日历框选项的数字编辑框的 GUI 时我不能用那个。</P><P>以下是我目前使用的问题和解决方案的几个示例,具体取决于 JMP 版本:</P><DIV class="lia-spoiler-container"><A class="lia-spoiler-link" href="#" rel="nofollow noopener noreferrer" target="_blank">查看更多...</A><NOSCRIPT>(重点阅读)</NOSCRIPT><DIV class="lia-spoiler-border"><DIV class="lia-spoiler-content"><PRE><CODE class=" language-jsl">Names Default To Here(1);
Clear Log();
Print("New window");
nw = New Window("", Lineup Box(N Col(2),
Text Box("Format Pattern
我使用 JMP16 的结果:
我已经创建了 JMP 支持功能请求,要求在 JMP 中设置通用时间格式选项(区域设置日期时间或 ISO 格式),但支持人员对它的实施不太抱有希望(也许如果我创建了一个愿望清单项目和它获得了荣誉,它可能会获得更好的机会)。
并重复这个问题:
您是否遇到过这些日期和时间问题?当用户具有不同的区域设置时,您是如何处理这些问题的?
编辑:
使用 JMP16 Pro 从我的工作笔记本电脑格式化设置:
从我的另一台电脑上使用 JMP15 使用非常奇怪的日期格式:
数据表脚本编写此行为最迟将在 JMP17 中更改。 下面是它在 JMP17 中应该如何工作的示例:
Format(Today(), "Locale Date Time h:m:s"); = "12/07/2021 16.07.20"
Format(Today(), "Locale Date Time h.m.s"); = "12/07/2021 16.07.20"
在 JMP17 之前,我将使用格式模式 (JMP16) 或我的语言环境日期构建方法