Time.FromText

語法

Time.FromText(text as nullable text, optional options as any) as nullable time

關於

從文字表示法 time 建立 text 值。 可以提供選用的record參數options來指定其他屬性。 record 可以包含下列欄位:

  • Format:text 值,指出要使用的格式。 如需詳細資訊,請移至 標準日期和時間格式字串,自定義日期和時間格式字串。 省略此欄位或提供 null,則會竭盡所能剖析時間。
  • Culture:當 Format 不是 null 時,Culture 控制某些格式規範。 例如,在 "en-US" 中,"tt" 為 "AM" or "PM",而在 "ar-EG" 中,"tt" 為 "ص" or "م"。 當 Format 為 null 時,Culture 會控制要使用的預設格式。 當 Culture 是 null 或被省略時,將使用 Culture.Current。

若要支援舊版工作流程,options 也可能是文字值。 這具有與 options = [Format = null, Culture = options] 相同的行為。

範例 1

將 "10:12:31am" 轉換為時間值。

使用方式

Time.FromText("10:12:31am")

輸出

#time(10, 12, 31)

範例 2

將 "1012" 轉換為時間值。

使用方式

Time.FromText("1012")

輸出

#time(10, 12, 00)

範例 3

將 "10" 轉換為時間值。

使用方式

Time.FromText("10")

輸出

#time(10, 00, 00)