如何在列公式中将 UTC 时间戳转换为本地时间
大家好,
I have a column Timestamp UTC in JMP with values like 2025-10-31T08:30:00.
I want to create a new column Timestamp Local that converts this UTC time to local time
Is there a simple formula-based way to add 5.5 hours to my timestamp directly in a 列公式, without scripting or using Date Add?
例如:
Informat(:Timestamp UTC, "yyyy-mm-ddThh:mm:ss") + (4 * 3600)
但我不太确定这种语法是否正确,因为它既没有产生结果也没有产生公式求值错误。
我还尝试了根据一个讨论帖提出的方法:
<'T'>
<HH24>
<::>
<MM>
<::>
<SS>
Z") + (4 * 3600)
</SS>
</MM>
</HH24>
无结果
公式如下:
Also tried Format - "yyyy-mm-ddThh:mm:ss"
col_name_list = Current Data Table() << get column names( string );
If(
!Contains(col_name_list, "Timestamp Local"),
Current Data Table() << New Column(
"Timestamp Local",
Numeric,
Continuous,
Format("m/d/y h:m:s"),
Formula(
Informat(:Name("Timestamp UTC"),
//"Format Pattern",
"yyyy-mm-ddThh:mm:ss") + (4* 3600)
)
)
);
Informat(:Timestamp UTC, "Format Pattern", "
<YYYY>
<->
<MM>
<->
</MM>
</YYYY>
希望能得到一些指导或示例,说明如何在列公式中干净利落地处理 UTC 到本地时间的转换。
谢谢!
自动化和脚本编写基础数据分析与建模数据融合与清理回复:如何在列公式中将 UTC 时间戳转换为本地时间这是否可行?
![TimeAdd_2025-11-03 13_22_07-Time Plus - JMP [2].png TimeAdd_2025-11-03 13_22_07-Time Plus - JMP [2].png](https://us.v-cdn.net/6038925/uploads/images/86259i38E814A6E03787A1/TimeAdd_2025-11-03%2013_22_07-Time%20Plus%20-%20JMP%20%5B2%5D.png)
</CODE></PRE>
<P> </P>
<PRE><CODE class=" language-jsl">New Column( "Time Plus",
Numeric,
"Continuous",
Format( "yyyy-mm-ddThh:mm:ss", 19, 0 ),
Input Format( "yyyy-mm-ddThh:mm:ss", 0 ),
Formula( :Timestamp + In Hours( 5.5 ) ),
Set Selected
)
回复:如何在列公式中将 UTC 时间戳转换为本地时间New Table( "Untitled",
Add Rows( 2 ),
New Column( "old", Character, "Nominal", Set Values( {"2025-10-31T08:30:00", "2025-10-31T08:30:01"} ), Set Display Width( 153 ) ),
New Column( "new",
Numeric,
"Continuous",
Format( "Monddyyyy h:m:s", 22, 0 ),
Input Format( "Monddyyyy h:m:s", 0 ),
Formula( Informat( :old, "yyyy-mm-ddThh:mm:ss" ) + In Hours( 5.5 ) )
)
)

JMP 将日期时间值存储为自 1904 年以来的秒数。InHours 函数返回 3600 乘以参数。我假设你的 Timestamp 列中包含字符数据(在我的示例中为 old)。
回复:如何在列公式中将 UTC 时间戳转换为本地时间我应该把这个也加上作为参考。
由于这是来自原始数据——建模类型——连续型
格式定义如下:
Format("m/d/y h:m:s")
回复:如何在列公式中将 UTC 时间戳转换为本地时间我应该把这个也加上作为参考。
由于这是来自原始数据——建模类型——连续型
格式定义如下:
Format("m/d/y h:m:s")<BR /><BR />I tried the formula above, it didn't yeild any output. I will check again.
回复:如何在列公式中将 UTC 时间戳转换为本地时间@mlo1 @Craige_Hales
这招奏效了。
col_name_list = Current Data Table() << get column names( string );
If( !Contains( col_name_list, "Timestamp Local" ), //If the column name doesn't exist in the array col_name_list
Current Data Table() << New Column(
"Timestamp Local",
Numeric,
"Continuous",
Format( "m/d/y h:m:s", 22, 0),
//Input Format( "Monddyyyy h:m:s", 0 ),
Formula(
//In Format( :Timestamp UTC, "yyyy-mm-ddThh:mm:ss" ) + In Hours( 5.5 )
Informat( Substitute(:Timestamp UTC, "+00:00", ""), "yyyy-mm-dd hh:mm:ss" ) + In Hours(5.5)
),
//Formula( :Timestamp + In Hours( 5.5 ) ),
//Set Selected
)
);<BR /><BR />
| UTC时间 |
当地时间 |
| 2025-09-14 07:51:52+00:00 |
2025年9月14日 下午1:21:52 |
| 2025-09-14 07:56:52+00:00 |
2025年9月14日 下午1:26:52 |
回复:如何在列公式中将 UTC 时间戳转换为本地时间然而,这个公式行不通。
If(!Contains(col_name_list, "Max Timestamp UTC"),
Current Data Table() << New Column(
"Max Timestamp UTC",
Numeric,
Continuous,
Format("m/d/y h:m:s", 22, 0),
Formula(
Col Maximum(
:Name("Timestamp UTC"),
/*Informat(
Substitute(:Name("Timestamp UTC"), "+00:00", ""),
"yyyy-mm-dd hh:mm:ss"
),*/
:Name("ID")
)
)
)
);
原样版本中,注释掉的代码部分似乎运行时间更长,并且进入了无限循环,导致我的 JMP 没有响应,我不得不强制关闭应用程序。
我之前也做过类似的事情,但是没有使用下面的代码就生成了本地时间戳。
:Name("Timestamp UTC") << Data Type(Character) << Modeling Type(Nominal);
回复:如何在列公式中将 UTC 时间戳转换为本地时间您使用的是哪个 JMP 版本?如果您在使用 Col Max 时遇到速度问题,我建议您首先创建一个单独的列。
Informat(Substitute(:"Timestamp UTC"n, "+00:00", ""), "yyyy-mm-dd hh:mm:ss")
然后将新创建的列用作变量。
回复:如何在列公式中将 UTC 时间戳转换为本地时间是的,我试过了。
dt:Name( "Timestamp UTC" ) << Informat(
Substitute( :Timestamp UTC, "+00:00", "" ),
"yyyy-mm-dd hh:mm:ss"
);
dt:Name( "Timestamp UTC" ) << Data Type( Character ) << Modeling Type( Nominal );
col_name_list = Current Data Table() << get column names ( string );
If( !Contains(col_name_list, "Timestamp UTC (Numeric)"),
Current Data Table() << New Column(
"Timestamp UTC (Numeric)",
Numeric,
"Continuous",
Format("m/d/y h:m:s", 22, 0),
Formula(
Informat( Substitute(:Timestamp UTC, "+00:00", ""), "yyyy-mm-dd hh:mm:ss" )
)
)
);
dt:Name("Timestamp UTC (Numeric)") << Delete Formula;
dt:Name("Timestamp UTC") <<
Set Values(:Name("Timestamp UTC (Numeric)")) <<
Data Type(Numeric) <<
Format("m/d/y h:m:s", 22, 0);
我正在尝试这个操作。它覆盖了我的时间戳(UTC)列,并且没有值。
回复:如何在列公式中将 UTC 时间戳转换为本地时间能否提供一下你正在使用的表格示例?只需要时间戳列就足够了(另外,记得删除表格变量/脚本)。
回复:如何在列公式中将 UTC 时间戳转换为本地时间@jthi请参考这个解决方案。我发现创建一个额外的列并使用它非常方便。