如何在列公式中將 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請參考這個解決方案。我發現創建一個額外的列並使用它非常方便。