共用方式為


DateTimeZone.ToText

語法

DateTimeZone.ToText(dateTimeZone as nullable datetimezone, optional options as any, optional culture as nullable text) as nullable text

關於

傳回 dateTimeZone 的文字表示。 您可以提供選用 record 參數 options 來指定其他屬性。 culture 僅適用於舊版工作流程。 record 可包含下列欄位:

  • Formattext 值,指出要使用的格式。 如需其他詳細資料,請前往 https://go.microsoft.com/fwlink/?linkid=2180104https://go.microsoft.com/fwlink/?linkid=2180105。 省略此欄位或提供 null 會導致使用 Culture 所定義的預設值將日期格式化。

  • Culture:當 Format 不是 null 時,Culture 會控制某些格式規範。 例如, 中的 "en-US" 是 ,而中的 "MMM" "ru-RU""янв", "фев", "мар", ..."Jan", "Feb", "Mar", ..."MMM"Formatnull 時,Culture 會控制要使用的預設格式。 當 Culturenull 或將其省略時,會使用 Culture.Current

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

範例 1

#datetimezone(2010, 12, 31, 01, 30, 25, 2, 0) 轉換為 text 值。 結果輸出可能會有所不同,取決於目前的文化特性。

使用方式

DateTimeZone.ToText(#datetimezone(2010, 12, 31, 01, 30, 25, 2, 0))

輸出

"12/31/2010 1:30:25 AM +02:00"

範例 2

使用自訂格式和德文文化特性進行轉換。

使用方式

DateTimeZone.ToText(#datetimezone(2010, 12, 30, 2, 4, 50.36973, -8,0), [Format="dd MMM yyyy HH:mm:ss.ffffff zzz", Culture="de-DE"])

輸出

"30 Dez 2010 02:04:50.369730 -08:00"

範例 3

使用 ISO 8601 模式進行轉換。

使用方式

DateTimeZone.ToText(#datetimezone(2000, 2, 8, 3, 45, 12, 2, 0),[Format="O", Culture="en-US"])

輸出

"2000-02-08T03:45:12.0000000+02:00"