Time.FromText

语法

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

关于

从文本表示形式 text 创建一个 time 值。 可以提供可选 record 参数 options 来指定额外的属性。 record 可以包含以下字段:

  • Format:一个 text 值,指示要使用的格式。 有关详细信息,请转到 https://go.microsoft.com/fwlink/?linkid=2180104https://go.microsoft.com/fwlink/?linkid=2180105。 省略此字段或提供 null 将导致尽最大努力分析时间。

  • Culture:如果 Format 不为 null,则 Culture 会控制某些格式说明符。 例如,在使用 "en-US" 时,"tt""AM" or "PM",而在使用 "ar-EG" 时,"tt""ص" or "م"。 当 Formatnull 时,Culture 控制要使用的默认格式。 当 Culturenull 或被省略时,将使用 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)