適用於 Adobe® Flash® Platform 的 ActionScript® 3.0 參考
首頁  |  隱藏套件和類別清單 |  套件  |  類別  |  新增內容  |  索引  |  附錄  |  為什麼顯示英文?
篩選: AIR 30.0 和更早版本, Flash Player 30.0 和更早版本, Flash Lite 4
Flex 4.6 和更早版本, Flash Pro CS6 和更早版本
隱藏篩選
flash.globalization 

DateTimeFormatter  - AS3

套件x

最上層
adobe.utils
air.desktop
air.net
air.update
air.update.events
coldfusion.air
coldfusion.air.errors
coldfusion.air.events
coldfusion.service
coldfusion.service.events
coldfusion.service.mxml
com.adobe.acm.solutions.authoring.domain.extensions
com.adobe.acm.solutions.ccr.domain.extensions
com.adobe.consulting.pst.vo
com.adobe.dct.component
com.adobe.dct.component.datadictionary
com.adobe.dct.component.datadictionaryElement
com.adobe.dct.component.dataElementsPanel
com.adobe.dct.component.toolbars
com.adobe.dct.event
com.adobe.dct.exp
com.adobe.dct.model
com.adobe.dct.service
com.adobe.dct.service.provider
com.adobe.dct.transfer
com.adobe.dct.util
com.adobe.dct.view
com.adobe.ep.taskmanagement.domain
com.adobe.ep.taskmanagement.event
com.adobe.ep.taskmanagement.filter
com.adobe.ep.taskmanagement.services
com.adobe.ep.taskmanagement.util
com.adobe.ep.ux.attachmentlist.component
com.adobe.ep.ux.attachmentlist.domain
com.adobe.ep.ux.attachmentlist.domain.events
com.adobe.ep.ux.attachmentlist.domain.renderers
com.adobe.ep.ux.attachmentlist.skin
com.adobe.ep.ux.attachmentlist.skin.renderers
com.adobe.ep.ux.content.event
com.adobe.ep.ux.content.factory
com.adobe.ep.ux.content.handlers
com.adobe.ep.ux.content.managers
com.adobe.ep.ux.content.model.asset
com.adobe.ep.ux.content.model.preview
com.adobe.ep.ux.content.model.relation
com.adobe.ep.ux.content.model.search
com.adobe.ep.ux.content.model.toolbar
com.adobe.ep.ux.content.search
com.adobe.ep.ux.content.services
com.adobe.ep.ux.content.services.load
com.adobe.ep.ux.content.services.permissions
com.adobe.ep.ux.content.services.preview
com.adobe.ep.ux.content.services.providers
com.adobe.ep.ux.content.services.query
com.adobe.ep.ux.content.services.relationships
com.adobe.ep.ux.content.services.search.lccontent
com.adobe.ep.ux.content.services.version
com.adobe.ep.ux.content.view
com.adobe.ep.ux.content.view.components.activate
com.adobe.ep.ux.content.view.components.grid
com.adobe.ep.ux.content.view.components.grid.hover
com.adobe.ep.ux.content.view.components.grid.hover.component
com.adobe.ep.ux.content.view.components.grid.renderers
com.adobe.ep.ux.content.view.components.relationships
com.adobe.ep.ux.content.view.components.review
com.adobe.ep.ux.content.view.components.search.renderers
com.adobe.ep.ux.content.view.components.searchpod
com.adobe.ep.ux.content.view.components.toolbar
com.adobe.ep.ux.content.view.components.toolbar.controlRenderers
com.adobe.ep.ux.content.view.components.version
com.adobe.ep.ux.documentsubmit.component
com.adobe.ep.ux.documentsubmit.domain
com.adobe.ep.ux.documentsubmit.skin
com.adobe.ep.ux.taskaction.component
com.adobe.ep.ux.taskaction.domain
com.adobe.ep.ux.taskaction.domain.events
com.adobe.ep.ux.taskaction.skin
com.adobe.ep.ux.taskdetails.component
com.adobe.ep.ux.taskdetails.domain
com.adobe.ep.ux.taskdetails.skin
com.adobe.ep.ux.tasklist.component
com.adobe.ep.ux.tasklist.domain
com.adobe.ep.ux.tasklist.skin
com.adobe.ep.ux.webdocumentviewer.domain
com.adobe.exm.expression
com.adobe.exm.expression.error
com.adobe.exm.expression.event
com.adobe.exm.expression.impl
com.adobe.fiber.runtime.lib
com.adobe.fiber.services
com.adobe.fiber.services.wrapper
com.adobe.fiber.styles
com.adobe.fiber.util
com.adobe.fiber.valueobjects
com.adobe.gravity.binding
com.adobe.gravity.context
com.adobe.gravity.flex.bundleloader
com.adobe.gravity.flex.progress
com.adobe.gravity.flex.serviceloader
com.adobe.gravity.framework
com.adobe.gravity.init
com.adobe.gravity.service.bundleloader
com.adobe.gravity.service.logging
com.adobe.gravity.service.manifest
com.adobe.gravity.service.progress
com.adobe.gravity.tracker
com.adobe.gravity.ui
com.adobe.gravity.utility
com.adobe.gravity.utility.async
com.adobe.gravity.utility.error
com.adobe.gravity.utility.events
com.adobe.gravity.utility.factory
com.adobe.gravity.utility.flex.async
com.adobe.gravity.utility.logging
com.adobe.gravity.utility.message
com.adobe.gravity.utility.sequence
com.adobe.gravity.utility.url
com.adobe.guides.control
com.adobe.guides.domain
com.adobe.guides.i18n
com.adobe.guides.spark.components.skins
com.adobe.guides.spark.components.skins.mx
com.adobe.guides.spark.headers.components
com.adobe.guides.spark.headers.skins
com.adobe.guides.spark.layouts.components
com.adobe.guides.spark.layouts.skins
com.adobe.guides.spark.navigators.components
com.adobe.guides.spark.navigators.renderers
com.adobe.guides.spark.navigators.skins
com.adobe.guides.spark.util
com.adobe.guides.spark.wrappers.components
com.adobe.guides.spark.wrappers.skins
com.adobe.guides.submit
com.adobe.icc.dc.domain
com.adobe.icc.dc.domain.factory
com.adobe.icc.editors.events
com.adobe.icc.editors.handlers
com.adobe.icc.editors.managers
com.adobe.icc.editors.model
com.adobe.icc.editors.model.config
com.adobe.icc.editors.model.el
com.adobe.icc.editors.model.el.operands
com.adobe.icc.editors.model.el.operators
com.adobe.icc.enum
com.adobe.icc.external.dc
com.adobe.icc.obj
com.adobe.icc.services
com.adobe.icc.services.category
com.adobe.icc.services.config
com.adobe.icc.services.download
com.adobe.icc.services.export
com.adobe.icc.services.external
com.adobe.icc.services.formbridge
com.adobe.icc.services.fragmentlayout
com.adobe.icc.services.layout
com.adobe.icc.services.letter
com.adobe.icc.services.locator
com.adobe.icc.services.module
com.adobe.icc.services.render
com.adobe.icc.services.submit
com.adobe.icc.services.user
com.adobe.icc.token
com.adobe.icc.vo
com.adobe.icc.vo.render
com.adobe.icomm.assetplacement.controller
com.adobe.icomm.assetplacement.controller.utils
com.adobe.icomm.assetplacement.data
com.adobe.icomm.assetplacement.model
com.adobe.livecycle.assetmanager.client
com.adobe.livecycle.assetmanager.client.event
com.adobe.livecycle.assetmanager.client.handler
com.adobe.livecycle.assetmanager.client.managers
com.adobe.livecycle.assetmanager.client.model
com.adobe.livecycle.assetmanager.client.model.cms
com.adobe.livecycle.assetmanager.client.service
com.adobe.livecycle.assetmanager.client.service.search
com.adobe.livecycle.assetmanager.client.service.search.cms
com.adobe.livecycle.assetmanager.client.utils
com.adobe.livecycle.content
com.adobe.livecycle.rca.model
com.adobe.livecycle.rca.model.constant
com.adobe.livecycle.rca.model.document
com.adobe.livecycle.rca.model.participant
com.adobe.livecycle.rca.model.reminder
com.adobe.livecycle.rca.model.stage
com.adobe.livecycle.rca.service
com.adobe.livecycle.rca.service.core
com.adobe.livecycle.rca.service.core.delegate
com.adobe.livecycle.rca.service.process
com.adobe.livecycle.rca.service.process.delegate
com.adobe.livecycle.rca.token
com.adobe.livecycle.ria.security.api
com.adobe.livecycle.ria.security.service
com.adobe.mosaic.layouts
com.adobe.mosaic.layouts.dragAndDrop
com.adobe.mosaic.layouts.interfaces
com.adobe.mosaic.mxml
com.adobe.mosaic.om.constants
com.adobe.mosaic.om.events
com.adobe.mosaic.om.impl
com.adobe.mosaic.om.interfaces
com.adobe.mosaic.skinning
com.adobe.mosaic.sparklib.editors
com.adobe.mosaic.sparklib.optionMenu
com.adobe.mosaic.sparklib.scrollableMenu
com.adobe.mosaic.sparklib.scrollableMenu.skins
com.adobe.mosaic.sparklib.tabLayout
com.adobe.mosaic.sparklib.tabLayout.events
com.adobe.mosaic.sparklib.tabLayout.layouts
com.adobe.mosaic.sparklib.tabLayout.skins
com.adobe.mosaic.sparklib.text
com.adobe.mosaic.sparklib.util
com.adobe.solutions.acm.authoring.presentation
com.adobe.solutions.acm.authoring.presentation.actionbar
com.adobe.solutions.acm.authoring.presentation.common
com.adobe.solutions.acm.authoring.presentation.events
com.adobe.solutions.acm.authoring.presentation.fragment
com.adobe.solutions.acm.authoring.presentation.letter
com.adobe.solutions.acm.authoring.presentation.letter.data
com.adobe.solutions.acm.authoring.presentation.preview
com.adobe.solutions.acm.authoring.presentation.rte
com.adobe.solutions.acm.ccr.presentation
com.adobe.solutions.acm.ccr.presentation.contentcapture
com.adobe.solutions.acm.ccr.presentation.contentcapture.events
com.adobe.solutions.acm.ccr.presentation.contentcapture.preview
com.adobe.solutions.acm.ccr.presentation.datacapture
com.adobe.solutions.acm.ccr.presentation.datacapture.renderers
com.adobe.solutions.acm.ccr.presentation.pdf
com.adobe.solutions.exm
com.adobe.solutions.exm.authoring
com.adobe.solutions.exm.authoring.components.controls
com.adobe.solutions.exm.authoring.components.toolbars
com.adobe.solutions.exm.authoring.domain
com.adobe.solutions.exm.authoring.domain.expression
com.adobe.solutions.exm.authoring.domain.impl
com.adobe.solutions.exm.authoring.domain.method
com.adobe.solutions.exm.authoring.domain.variable
com.adobe.solutions.exm.authoring.enum
com.adobe.solutions.exm.authoring.events
com.adobe.solutions.exm.authoring.model
com.adobe.solutions.exm.authoring.renderer
com.adobe.solutions.exm.authoring.view
com.adobe.solutions.exm.expression
com.adobe.solutions.exm.impl
com.adobe.solutions.exm.impl.method
com.adobe.solutions.exm.method
com.adobe.solutions.exm.mock
com.adobe.solutions.exm.mock.method
com.adobe.solutions.exm.runtime
com.adobe.solutions.exm.runtime.impl
com.adobe.solutions.exm.variable
com.adobe.solutions.prm.constant
com.adobe.solutions.prm.domain
com.adobe.solutions.prm.domain.factory
com.adobe.solutions.prm.domain.impl
com.adobe.solutions.prm.domain.manager
com.adobe.solutions.prm.presentation.asset
com.adobe.solutions.prm.presentation.constant
com.adobe.solutions.prm.presentation.document
com.adobe.solutions.prm.presentation.event
com.adobe.solutions.prm.presentation.file
com.adobe.solutions.prm.presentation.project
com.adobe.solutions.prm.presentation.team
com.adobe.solutions.prm.presentation.util
com.adobe.solutions.prm.service
com.adobe.solutions.prm.services.impl
com.adobe.solutions.prm.vo
com.adobe.solutions.rca.constant
com.adobe.solutions.rca.domain
com.adobe.solutions.rca.domain.common
com.adobe.solutions.rca.domain.factory
com.adobe.solutions.rca.domain.impl
com.adobe.solutions.rca.domain.impl.manager
com.adobe.solutions.rca.domain.manager
com.adobe.solutions.rca.presentation
com.adobe.solutions.rca.presentation.comment
com.adobe.solutions.rca.presentation.constant
com.adobe.solutions.rca.presentation.event
com.adobe.solutions.rca.presentation.gantt
com.adobe.solutions.rca.presentation.gantt.ruler
com.adobe.solutions.rca.presentation.template
com.adobe.solutions.rca.presentation.template.audit
com.adobe.solutions.rca.presentation.template.definition
com.adobe.solutions.rca.presentation.template.documents
com.adobe.solutions.rca.presentation.template.stages
com.adobe.solutions.rca.presentation.util
com.adobe.solutions.rca.service
com.adobe.solutions.rca.services.impl
com.adobe.solutions.rca.vo
com.adobe.solutions.rca.vo.um
com.adobe.viewsource
fl.accessibility
fl.containers
fl.controls
fl.controls.dataGridClasses
fl.controls.listClasses
fl.controls.progressBarClasses
fl.core
fl.data
fl.display
fl.events
fl.ik
fl.lang
fl.livepreview
fl.managers
fl.motion
fl.motion.easing
fl.rsl
fl.text
fl.transitions
fl.transitions.easing
fl.video
flash.accessibility
flash.concurrent
flash.crypto
flash.data
flash.desktop
flash.display
flash.display3D
flash.display3D.textures
flash.errors
flash.events
flash.external
flash.filesystem
flash.filters
flash.geom
flash.globalization
flash.html
flash.media
flash.net
flash.net.dns
flash.net.drm
flash.notifications
flash.permissions
flash.printing
flash.profiler
flash.sampler
flash.security
flash.sensors
flash.system
flash.text
flash.text.engine
flash.text.ime
flash.ui
flash.utils
flash.xml
flashx.textLayout
flashx.textLayout.compose
flashx.textLayout.container
flashx.textLayout.conversion
flashx.textLayout.edit
flashx.textLayout.elements
flashx.textLayout.events
flashx.textLayout.factory
flashx.textLayout.formats
flashx.textLayout.operations
flashx.textLayout.utils
flashx.undo
ga.controls
ga.layouts
ga.model
ga.uiComponents
ga.util
ga.views
ga.wrappers
lc.foundation
lc.foundation.domain
lc.foundation.events
lc.foundation.ui
lc.foundation.util
lc.preloader
lc.procmgmt
lc.procmgmt.commands
lc.procmgmt.domain
lc.procmgmt.events
lc.procmgmt.formbridge
lc.procmgmt.impl
lc.procmgmt.ui.attachments
lc.procmgmt.ui.controls
lc.procmgmt.ui.controls.card
lc.procmgmt.ui.controls.renderer
lc.procmgmt.ui.help
lc.procmgmt.ui.layout
lc.procmgmt.ui.presentationmodel
lc.procmgmt.ui.process
lc.procmgmt.ui.search
lc.procmgmt.ui.startpoint
lc.procmgmt.ui.task
lc.procmgmt.ui.task.form
lc.procmgmt.ui.task.form.commands
lc.procmgmt.ui.tracking
mx.accessibility
mx.automation
mx.automation.air
mx.automation.delegates
mx.automation.delegates.advancedDataGrid
mx.automation.delegates.charts
mx.automation.delegates.containers
mx.automation.delegates.controls
mx.automation.delegates.controls.dataGridClasses
mx.automation.delegates.controls.fileSystemClasses
mx.automation.delegates.core
mx.automation.delegates.flashflexkit
mx.automation.events
mx.binding
mx.binding.utils
mx.charts
mx.charts.chartClasses
mx.charts.effects
mx.charts.effects.effectClasses
mx.charts.events
mx.charts.renderers
mx.charts.series
mx.charts.series.items
mx.charts.series.renderData
mx.charts.styles
mx.collections
mx.collections.errors
mx.containers
mx.containers.accordionClasses
mx.containers.dividedBoxClasses
mx.containers.errors
mx.containers.utilityClasses
mx.controls
mx.controls.advancedDataGridClasses
mx.controls.dataGridClasses
mx.controls.listClasses
mx.controls.menuClasses
mx.controls.olapDataGridClasses
mx.controls.scrollClasses
mx.controls.sliderClasses
mx.controls.textClasses
mx.controls.treeClasses
mx.controls.videoClasses
mx.core
mx.core.windowClasses
mx.data
mx.data.crypto
mx.data.errors
mx.data.events
mx.data.messages
mx.data.mxml
mx.data.offline.errors
mx.data.utils
mx.effects
mx.effects.easing
mx.effects.effectClasses
mx.events
mx.filters
mx.flash
mx.formatters
mx.geom
mx.graphics
mx.graphics.codec
mx.graphics.shaderClasses
mx.logging
mx.logging.errors
mx.logging.targets
mx.managers
mx.messaging
mx.messaging.channels
mx.messaging.config
mx.messaging.errors
mx.messaging.events
mx.messaging.management
mx.messaging.messages
mx.modules
mx.netmon
mx.olap
mx.olap.aggregators
mx.preloaders
mx.printing
mx.resources
mx.rpc
mx.rpc.events
mx.rpc.http
mx.rpc.http.mxml
mx.rpc.livecycle
mx.rpc.mxml
mx.rpc.remoting
mx.rpc.remoting.mxml
mx.rpc.soap
mx.rpc.soap.mxml
mx.rpc.wsdl
mx.rpc.xml
mx.skins
mx.skins.halo
mx.skins.spark
mx.skins.wireframe
mx.skins.wireframe.windowChrome
mx.states
mx.styles
mx.utils
mx.validators
org.osmf.containers
org.osmf.display
org.osmf.elements
org.osmf.events
org.osmf.layout
org.osmf.logging
org.osmf.media
org.osmf.metadata
org.osmf.net
org.osmf.net.dvr
org.osmf.net.httpstreaming
org.osmf.net.metrics
org.osmf.net.qos
org.osmf.net.rtmpstreaming
org.osmf.net.rules
org.osmf.traits
org.osmf.utils
spark.accessibility
spark.automation.delegates
spark.automation.delegates.components
spark.automation.delegates.components.gridClasses
spark.automation.delegates.components.mediaClasses
spark.automation.delegates.components.supportClasses
spark.automation.delegates.skins.spark
spark.automation.events
spark.collections
spark.components
spark.components.calendarClasses
spark.components.gridClasses
spark.components.mediaClasses
spark.components.supportClasses
spark.components.windowClasses
spark.core
spark.effects
spark.effects.animation
spark.effects.easing
spark.effects.interpolation
spark.effects.supportClasses
spark.events
spark.filters
spark.formatters
spark.formatters.supportClasses
spark.globalization
spark.globalization.supportClasses
spark.layouts
spark.layouts.supportClasses
spark.managers
spark.modules
spark.preloaders
spark.primitives
spark.primitives.supportClasses
spark.skins
spark.skins.mobile
spark.skins.mobile.supportClasses
spark.skins.spark
spark.skins.spark.mediaClasses.fullScreen
spark.skins.spark.mediaClasses.normal
spark.skins.spark.windowChrome
spark.skins.wireframe
spark.skins.wireframe.mediaClasses
spark.skins.wireframe.mediaClasses.fullScreen
spark.transitions
spark.utils
spark.validators
spark.validators.supportClasses
xd.core.axm.enterprise.view.components
xd.core.axm.enterprise.view.skins
xd.core.axm.view.components
xd.core.axm.view.components.support

語言元素

全域常數
全域函數
運算子
陳述式、關鍵字和指令
特殊類型

附錄

新增內容
編譯器錯誤
編譯器警告
執行階段錯誤
移轉至 ActionScript 3
支援的字元集
僅限 MXML 標籤
移動 XML 元素
Timed Text 標籤
不建議元素清單
AccessibilityImplementation 常數
如何使用 ActionScript 範例
法律聲明
套件flash.globalization
類別public final class DateTimeFormatter
繼承DateTimeFormatter Inheritance Object

語言版本: ActionScript 3.0
執行階段版本: Flash Player 10.1, AIR 2

DateTimeFormatter 類別對於 Date 物件提供依地區而不同的格式設定,並存取當地語系化的日期欄位名稱。此類別的方法使用作業系統提供的函數與設定。

您可使用兩種方式選擇日期時間格式:使用預先定義的樣式或自訂樣式。對大部分的應用程式而言,應使用 DateTimeStyle 常數 (LONGMEDIUMNONESHORT) 所指定的預先定義樣式。這些常數會指定所要求地區設定的預設樣式,或以使用者作業系統設定為基礎的預設樣式。

例如,下列程式碼會使用預設簡短日期格式建立日期字串:

 
     var df:DateTimeFormatter = new DateTimeFormatter(LocaleID.DEFAULT, DateTimeStyle.SHORT, DateTimeStyle.NONE);
     var currentDate:Date = new Date();
     var shortDate:String = df.format(currentDate);
     

建立此類別的實體後,若作業系統支援要求的地區設定,則會根據要求的地區設定的慣例和預設值與建構函式的 dateStyletimeStyle 參數,設定實體屬性。若無法使用所要求的地區設定,則會根據後援或預設系統地區設定 (可使用 actualLocaleIDName 屬性擷取) 設定屬性。

此類別還有其他方法,可取得月份與星期別的當地語系化字串,並擷取每週第一天,以便在月曆挑選器或其他類似應用程式中使用。

由於所用的使用者設定、作業系統提供的格式化樣式,以及不支援所要求地區設定時所用的後援地區設定之不同,即使是使用相同的地區設定 ID,不同使用者也會看到不同的格式化結果。

檢視範例

相關 API 元素



公用屬性
 屬性定義自
  actualLocaleIDName : String
[唯讀] 此 DateTimeFormatter 物件所使用的實際地區設定 ID 名稱。
DateTimeFormatter
 Inheritedconstructor : Object
類別物件的參照或是特定物件實體的建構函數。
Object
  lastOperationStatus : String
[唯讀] 此 DateTimeFormatter 物件執行之上一個作業的狀態。
DateTimeFormatter
  requestedLocaleIDName : String
[唯讀] 傳送到此 DateTimeFormatter 物件建構函式的所要求地區設定 ID 名稱。
DateTimeFormatter
公用方法
 方法定義自
  
DateTimeFormatter(requestedLocaleIDName:String, dateStyle:String = "long", timeStyle:String = "long")
建構新 DateTimeFormatter 物件,以根據指定地區設定的慣例和所提供的日期與時間格式樣式,格式化日期與時間。
DateTimeFormatter
  
format(dateTime:Date):String
針對解譯為使用者本地時間 (使用 Date 物件的本地時間組件,如:date、day, fullYear、hours、minutes、month 和 seconds) 的 Date 物件,格式化顯示字串。
DateTimeFormatter
  
根據 dateStyle、timeStyle 或 date time 樣式,針對解譯為 UTC 時間 (使用 Date 物件的 UTC 組件,如:dateUTC、dayUTC、fullYearUTC、hoursUTC、minutesUTC、monthUTC 和 secondsUTC) 的 Date 物件,格式化顯示字串。
DateTimeFormatter
  
[靜態] 列出此類別支援的所有地區設定 ID 名稱。
DateTimeFormatter
  
取得此 DateTimeFormatter 實體的日期樣式。
DateTimeFormatter
  
傳回此 DateTimeFormatter 物件用來格式化日期與時間的樣式字串。
DateTimeFormatter
  
傳回對應到此地區設定和月曆系統中每週第一天的整數。
DateTimeFormatter
  
getMonthNames(nameStyle:String = "full", context:String = "standalone"):Vector.<String>
擷取包含目前月曆系統月份名稱的當地語系化字串清單。
DateTimeFormatter
  
取得此 DateTimeFormatter 實體的時間樣式。
DateTimeFormatter
  
getWeekdayNames(nameStyle:String = "full", context:String = "standalone"):Vector.<String>
擷取包含目前月曆系統星期別名稱的當地語系化字串清單。
DateTimeFormatter
 Inherited
指出物件是否有已定義的指定屬性。
Object
 Inherited
指出 Object 類別的實體是否位於指定為參數的物件原型鏈中。
Object
 Inherited
指出指定的屬性是否存在,以及是否可列舉。
Object
  
設定此 DateTimeFormatter 物件用來格式化日期與時間的樣式字串。
DateTimeFormatter
  
setDateTimeStyles(dateStyle:String, timeStyle:String):void
設定此 DateTimeFormatter 實體的日期和時間樣式。
DateTimeFormatter
 Inherited
為迴圈作業設定動態屬性的可用性。
Object
 Inherited
傳回代表此物件的字串,根據地區特定慣例進行格式化。
Object
 Inherited
會傳回指定之物件的字串形式。
Object
 Inherited
會傳回指定之物件的基本值。
Object
屬性詳細資訊

actualLocaleIDName

屬性
actualLocaleIDName:String  [唯讀]

語言版本: ActionScript 3.0
執行階段版本: Flash Player 10.1, AIR 2

此 DateTimeFormatter 物件所使用的實際地區設定 ID 名稱。

根據作業系統與 requestedLocaleIDName 參數傳送到 Collator() 建構函式的值,此值有三種可能性。

  1. 若要求的地區設定不是 LocaleID.DEFAULT,而且作業系統支援要求的地區設定,則傳回的名稱會與 requestedLocaleIDName 屬性相同。
  2. 若使用 LocaleID.DEFAULT 當作建構函式 requestedLocaleIDName 參數的值,則會使用使用者作業系統指定的目前地區設定名稱。LocaleID.DEFAULT 值會將使用者的自訂設定保留於作業系統中。即使兩個地區設定 ID 名稱是相同的,傳送明確的值作為 requestedLocaleIDName 參數所得的結果,也未必與使用 LocaleID.DEFAULT 相同。使用者可能在自己的電腦上已有自訂的地區設定,若要求明確的地區設定 ID 名稱而不是使用 LocaleID.DEFAULT 的話,您的應用程式不會擷取這些自訂設定。
  3. 若系統不支援建構函式所指定的 requestedLocaleIDName,則會提供後援地區設定 ID 名稱。



實作
    public function get actualLocaleIDName():String

相關 API 元素

lastOperationStatus

屬性 
lastOperationStatus:String  [唯讀]

語言版本: ActionScript 3.0
執行階段版本: Flash Player 10.1, AIR 2

此 DateTimeFormatter 物件執行之上一個作業的狀態。只要呼叫此類別的建構函式或方法,或設定其他屬性,就會設定 lastOperationStatus 屬性。如需可能的值,請參閱各方法的說明。



實作
    public function get lastOperationStatus():String

相關 API 元素

requestedLocaleIDName

屬性 
requestedLocaleIDName:String  [唯讀]

語言版本: ActionScript 3.0
執行階段版本: Flash Player 10.1, AIR 2

傳送到此 DateTimeFormatter 物件建構函式的所要求地區設定 ID 名稱。

若使用 LocaleID.DEFAULT 值,則傳回的名稱會是 "i-default"。若採用後援地區設定,則所用的實際地區設定可能與要求的地區設定不同。您可以使用 actualLocaleIDName 屬性擷取實際地區設定名稱。



實作
    public function get requestedLocaleIDName():String

相關 API 元素

建構函式詳細資料

DateTimeFormatter

()建構函式
public function DateTimeFormatter(requestedLocaleIDName:String, dateStyle:String = "long", timeStyle:String = "long")

語言版本: ActionScript 3.0
執行階段版本: Flash Player 10.1, AIR 2

建構新 DateTimeFormatter 物件,以根據指定地區設定的慣例和所提供的日期與時間格式樣式,格式化日期與時間。日期和時間樣式用來設定預先定義的日期和時間格式化樣式,地區設定會根據作業系統樣式而有所不同。

此建構函式會判斷目前的作業系統是否支援要求的地區設定 ID 名稱。若不支援,則會改用後援地區設定。您可以從 actualLocaleIDName 屬性判斷後援地區設定 ID 的名稱。

requestedLocaleIDNamedateStyletimeStyle 其中一個參數使用後援,則會設定 lastOperationStatus 屬性指示後援類型。

若要根據使用者目前作業系統的偏好設定進行格式化,請將 requestedLocaleIDName 參數中的 LocaleID.DEFAULT 值傳送到建構函式。

當建構函式被呼叫並成功完成時,lastOperationStatus 屬性會被設為:

  • LastOperationStatus.NO_ERROR

若要求的地區設定 ID 名稱無法使用,則 lastOperationStatus 會被設為下列之一:

  • LastOperationStatus.USING_FALLBACK_WARNING
  • LastOperationStatus.USING_DEFAULT_WARNING

否則,lastOperationStatus 屬性會被設為 LastOperationStatus 類別中定義的常數之一。

如需有關上方列出的警告以及 lastOperationStatus 屬性的其他可能值的詳細資訊,請參閱 LastOperationStatus 類別的說明。

參數
requestedLocaleIDName:String — 判斷日期或時間格式時要使用的偏好地區設定 ID 名稱。
 
dateStyle:String (default = "long") — 指定格式化日期時要使用的樣式。值會對應到 DateTimeStyle 類別所列舉的值之一:
  • DateTimeStyle.LONG
  • DateTimeStyle.MEDIUM
  • DateTimeStyle.SHORT
  • DateTimeStyle.NONE
 
timeStyle:String (default = "long") — 指定格式化時間時要使用的樣式。值會對應到 DateTimeStyle 類別所列舉的值之一:
  • DateTimeStyle.LONG
  • DateTimeStyle.MEDIUM
  • DateTimeStyle.SHORT
  • DateTimeStyle.NONE

擲回值
ArgumentError — 若 dateStyletimeStyle 參數非有效的 DateTimeStyle 常數。
 
TypeError — 若 dateStyletimeStyle 參數為 null。

相關 API 元素

方法詳細資訊

format

()方法
public function format(dateTime:Date):String

語言版本: ActionScript 3.0
執行階段版本: Flash Player 10.1, AIR 2

針對解譯為使用者本地時間 (使用 Date 物件的本地時間組件,如:date、day, fullYear、hours、minutes、month 和 seconds) 的 Date 物件,格式化顯示字串。會使用此 DateTimeFormatter 實體中指定的地區設定 ID 和日期與時間樣式慣例,或自訂日期與時間樣式,完成格式化動作。

當此方法被呼叫並成功完成時,lastOperationStatus 屬性會被設為:

  • LastOperationStatus.NO_ERROR

否則,lastOperationStatus 屬性會被設為 LastOperationStatus 類別中定義的常數之一。

參數

dateTime:Date — 要格式化的 Date 值。有效範圍是從 1601 年 1 月 1 日到 30827 年 12 月 31 日。

傳回值
String — 代表日期或時間值的格式化字串。

相關 API 元素

formatUTC

()方法 
public function formatUTC(dateTime:Date):String

語言版本: ActionScript 3.0
執行階段版本: Flash Player 10.1, AIR 2

根據 dateStyle、timeStyle 或 date time 樣式,針對解譯為 UTC 時間 (使用 Date 物件的 UTC 組件,如:dateUTC、dayUTC、fullYearUTC、hoursUTC、minutesUTC、monthUTC 和 secondsUTC) 的 Date 物件,格式化顯示字串。會使用此 DateTimeFormatter 實體中指定的地區設定 ID 和日期與時間樣式慣例,或自訂日期與時間樣式,完成格式化動作。

當此方法被呼叫並成功完成時,lastOperationStatus 屬性會被設為:

  • LastOperationStatus.NO_ERROR

否則,lastOperationStatus 屬性會被設為 LastOperationStatus 類別中定義的常數之一。

參數

dateTime:Date — 要格式化的 Date 值。有效範圍是從 1601 年 1 月 1 日到 30827 年 12 月 31 日。

傳回值
String — 代表日期或時間值的格式化字串。

相關 API 元素

getAvailableLocaleIDNames

()方法 
public static function getAvailableLocaleIDNames():Vector.<String>

語言版本: ActionScript 3.0
執行階段版本: Flash Player 10.1, AIR 2

列出此類別支援的所有地區設定 ID 名稱。

若目前的作業系統不支援此類別,此方法會傳回 null 值。

當此方法被呼叫並成功完成時,lastOperationStatus 屬性會被設為:

  • LastOperationStatus.NO_ERROR

否則,lastOperationStatus 屬性會被設為 LastOperationStatus 類別中定義的常數之一。

傳回值
Vector.<String> — 包含此類別支援的所有地區設定 ID 名稱之字串向量。

相關 API 元素

getDateStyle

()方法 
public function getDateStyle():String

語言版本: ActionScript 3.0
執行階段版本: Flash Player 10.1, AIR 2

取得此 DateTimeFormatter 實體的日期樣式。日期樣式是用來從作業系統擷取預先定義的日期格式化樣式。DateTimeFormatter() 建構函式、setDateTimeStyles() 方法或 setDateTimePattern() 方法,都可設定日期樣式值。

當此方法被呼叫並成功完成時,lastOperationStatus 屬性會被設為:

  • LastOperationStatus.NO_ERROR

否則,lastOperationStatus 屬性會被設為 LastOperationStatus 類別中定義的常數之一。

傳回值
String — 此格式化程式的日期樣式字串。

可能的值有:

  • DateTimeStyle.LONG
  • DateTimeStyle.MEDIUM
  • DateTimeStyle.SHORT
  • DateTimeStyle.NONE
  • DateTimeStyle.CUSTOM

相關 API 元素

getDateTimePattern

()方法 
public function getDateTimePattern():String

語言版本: ActionScript 3.0
執行階段版本: Flash Player 10.1, AIR 2

傳回此 DateTimeFormatter 物件用來格式化日期與時間的樣式字串。

可使用下列三種方式設定此樣式:

  1. 透過建構函式中所用的 dateStyletimeStyle 參數
  2. 透過 setDateTimeStyles() 方法
  3. 透過 setDateTimePattern() 方法。

如需樣式語法的說明,請參閱 setDateTimePattern() 方法。

當此方法被呼叫並成功完成時,lastOperationStatus 屬性會被設為:

  • LastOperationStatus.NO_ERROR

否則,lastOperationStatus 屬性會被設為 LastOperationStatus 類別中定義的常數之一。

傳回值
String — 包含此 DateTimeFormatter 物件用來格式化日期與時間的樣式之字串。

相關 API 元素

getFirstWeekday

()方法 
public function getFirstWeekday():int

語言版本: ActionScript 3.0
執行階段版本: Flash Player 10.1, AIR 2

傳回對應到此地區設定和月曆系統中每週第一天的整數。0 值對應到星期日、1 對應到星期一,依此類推,6 對應到星期六。

當此方法被呼叫並成功完成時,lastOperationStatus 屬性會被設為:

  • LastOperationStatus.NO_ERROR

否則,lastOperationStatus 屬性會被設為 LastOperationStatus 類別中定義的常數之一。

傳回值
int — 對應到此地區設定和月曆系統中每週第一天的整數。

相關 API 元素

getMonthNames

()方法 
public function getMonthNames(nameStyle:String = "full", context:String = "standalone"):Vector.<String>

語言版本: ActionScript 3.0
執行階段版本: Flash Player 10.1, AIR 2

擷取包含目前月曆系統月份名稱的當地語系化字串清單。清單中第一個元素是年中第一個月份的名稱。

當此方法被呼叫並成功完成時,lastOperationStatus 屬性會被設為:

  • LastOperationStatus.NO_ERROR

否則,lastOperationStatus 屬性會被設為 LastOperationStatus 類別中定義的常數之一。

參數

nameStyle:String (default = "full") — 表示要使用的名稱字串樣式。有效值為:
  • DateTimeNameStyle.FULL
  • DateTimeNameStyle.LONG_ABBREVIATION
  • DateTimeNameStyle.SHORT_ABBREVIATION
 
context:String (default = "standalone") — 指出要在其中使用格式化字串之內容的代碼。此內容只有對某些地區設定才有影響。有效值為:
  • DateTimeNameContext.FORMAT
  • DateTimeNameContext.STANDALONE

傳回值
Vector.<String> — 包含指定地區設定、名稱樣式和內容之月份名稱的當地語系化字串向量。向量中位於索引 0 的第一個元素是年中第一個月份的名稱;下一個元素是年中第二個月份的名稱,依此類推。

擲回值
TypeError — 若 nameStylecontext 參數為 null。

相關 API 元素

getTimeStyle

()方法 
public function getTimeStyle():String

語言版本: ActionScript 3.0
執行階段版本: Flash Player 10.1, AIR 2

取得此 DateTimeFormatter 實體的時間樣式。時間樣式是用來從作業系統擷取預先定義的時間格式化樣式。DateTimeFormatter() 建構函式、setDateTimeStyles() 方法或 setDateTimePattern() 方法,都可設定時間樣式值。

當此方法被呼叫並成功完成時,lastOperationStatus 屬性會被設為:

  • LastOperationStatus.NO_ERROR

否則,lastOperationStatus 屬性會被設為 LastOperationStatus 類別中定義的常數之一。

傳回值
String — 此格式化程式的時間樣式字串。

可能的值有:

  • DateTimeStyle.LONG
  • DateTimeStyle.MEDIUM
  • DateTimeStyle.SHORT
  • DateTimeStyle.NONE
  • DateTimeStyle.CUSTOM

相關 API 元素

getWeekdayNames

()方法 
public function getWeekdayNames(nameStyle:String = "full", context:String = "standalone"):Vector.<String>

語言版本: ActionScript 3.0
執行階段版本: Flash Player 10.1, AIR 2

擷取包含目前月曆系統星期別名稱的當地語系化字串清單。清單中的第一個元素代表「星期日」的名稱。

當此方法被呼叫並成功完成時,lastOperationStatus 屬性會被設為:

  • LastOperationStatus.NO_ERROR

否則,lastOperationStatus 屬性會被設為 LastOperationStatus 類別中定義的常數之一。

參數

nameStyle:String (default = "full") — 表示要使用的名稱字串樣式。有效值為:
  • DateTimeNameStyle.FULL
  • DateTimeNameStyle.LONG_ABBREVIATION
  • DateTimeNameStyle.SHORT_ABBREVIATION
 
context:String (default = "standalone") — 指出要在其中使用格式化字串之內容的代碼。此內容只適用於隨內容變更月份名稱的特定地區設定。例如,在希臘文中,單獨顯示時的月份名稱以及與日期一同顯示時的月份名稱不一樣。有效值為:
  • DateTimeNameContext.FORMAT
  • DateTimeNameContext.STANDALONE

傳回值
Vector.<String> — 包含指定地區設定、名稱樣式和內容之月份名稱的當地語系化字串向量。向量中位於索引 0 的第一個元素是「星期日」的名稱,第二個元素是「星期一」的名稱,依此類推。

擲回值
TypeError — 若 nameStylecontext 參數為 null。

相關 API 元素

setDateTimePattern

()方法 
public function setDateTimePattern(pattern:String):void

語言版本: ActionScript 3.0
執行階段版本: Flash Player 10.1, AIR 2

設定此 DateTimeFormatter 物件用來格式化日期與時間的樣式字串。

可使用下列三種方式設定格式化日期所用的樣式:

  1. 透過建構函式中所用的 dateStyletimeStyle 參數
  2. 透過 setDateTimeStyles() 方法
  3. 透過此 setDateTimePattern() 方法。

此方法有個副作用,就是會覆寫此 DateTimeFormatter 物件的目前時間與日期樣式,並將其設為值 DateTimeStyle.CUSTOM

定義如何格式化日期和時間的樣式字串。樣式包含的字母序列,會在格式化字串中被取代為日期和時間值。例如,在樣式「yyyy/MM」中,「yyyy」字元會被取代為四位數年份,接著「/」字元,「MM」會被取代為二位數月份。

樣式中使用的許多字母都可重複多次,以產生不同輸出,如下表所說明。

若序列超出樣式支援的字母數上限,會對應回該樣式字母支援的最長序列。例如:

  • MMMMMM 會被取代為 MMMM
  • dddd 會被取代為 dd
  • EEEEEEE 會被取代為 EEEE
  • aa 會被取代為 a
  • hhh 會被取代為 hh
  • mmmm 會被取代為 mm

理論上,樣式最多可包含 255 個字元,但有些平台的限制更為嚴格。若樣式超出樣式字元限制,lastOperationStatus 屬性會設為值 LastOperationStatus.PATTERN_SYNTAX_ERROR

並非所有作業系統都支援所有可能的樣式。若有平台不支援某樣式,則會使用後援樣式,並設定 lastOperationStatus 屬性以指示使用後援。若無法提供合理的後援樣式,則會使用空字串,並設定 lastOperationStatus 屬性以表示不支援該樣式。

下表說明有效樣式字母及其意義。

樣式字母說明
G紀元。會被目前日期與月曆的紀元字串取代。並非所有作業系統都支援此樣式。在不支援紀元的作業系統中,輸入樣式的字母會被取代為空字串。

紀元樣式可有一至五個字母,解譯如下:

  • 若樣式字母數為一至三,會使用縮寫形式。
  • 若樣式字母數為四,格式會被解譯為完整形式。
  • 若樣式字母數為五,格式會被解譯為簡短縮寫。

使用「西曆」的範例 (對支援此樣式的作業系統而言):

  • G, GG, GGG = AD
  • GGGG = 西元
  • GGGGG = A
y年。若樣式字母數為二,會顯示年份的最後兩位數,否則字母數會決定位數。若年份值所需位數超過字母數所提供的位數,就會提供完整年份值。若字母數多過值所需的位數,則會以零填補年份值。下列清單顯示年份為 1 與 2005 的結果。

範例:

  • y = 1
  • y = 2005
  • yy = 01
  • yy = 05
  • yyyy = 0001 或 01,根據作業系統而定。
  • yyyy = 2005
  • yyyyy = 01 或 0001,根據作業系統而定。若多過四個 y,就會退回作業系統支援的最大位數。
  • yyyyy = 2005
M 年中月份。月份樣式可有一至五個字母,解譯如下:
  • 若樣式字母數為一,格式會被解譯為一或二位數的數值。
  • 若樣式字母數為二,格式會被解譯為二位數的數值。
  • 若樣式字母數為三,格式會被解譯為長縮寫。
  • 若樣式字母數為四,格式會被解譯為完整名稱。
  • 若樣式字母數為五,格式會被解譯為簡短縮寫。並非所有作業系統都支援此格式,若不支援,會退回使用長縮寫。

範例:

  • M = 7
  • MM = 07
  • MMM = Jul, 7月
  • MMMM = July, 7月
  • MMMMM = J 或 Jul, 7 或 7月,根據作業系統而定。
d 月份日期別。月中日期樣式可有一或二個字母,解譯如下:
  • 若樣式字母數為一,格式會被解譯為一或二位數的數值。
  • 若樣式字母數為二,格式會被解譯為二位數的數值。

範例:

  • d = 4
  • dd = 04
  • dd = 14
E星期別。星期別樣式可有一到五個字母,解譯如下:
  • 若樣式字母數為一到三,格式會被解譯為長縮寫。
  • 若樣式字母數為四,格式會被解譯為完整名稱。
  • 若樣式字母數為五,格式會被解譯為簡短縮寫。並非所有作業系統都支援此格式,若不支援,會退回使用長縮寫。

範例:

  • E, EE, EEE = 週二
  • EEEE = 星期二
  • EEEEE = 二或週二,根據作業系統而異。
Q季。某些平台不支援此樣式。季樣式可有一至四個字母,解譯如下:
  • 若樣式字母數為一,格式會被解譯為一位數的數值。
  • 若樣式字母數為二,格式會被解譯為二位數的數值。
  • 若樣式字母數為三,格式會被解譯為縮寫。
  • 若樣式字母數為四,格式會被解譯為完整名稱。

範例 (對支援此樣式的作業系統而言):

  • Q = 2
  • QQ = 02
  • QQQ = Q2
  • QQQQ = 第二季
w年中週別。某些平台不支援此樣式。年中週別樣式可有一至二個字母,解譯如下:
  • 若樣式字母數為一,格式會被解譯為一或二位數的數值。
  • 若樣式字母數為二,格式會被解譯為二位數的數值。

以一年的第二週為例 (對支援此樣式的作業系統而言):

  • w = 2
  • ww = 02
W月中週別。某些平台不支援此樣式。此樣式只允許一個字母。

以七月的第二週為例 (對支援此樣式的作業系統而言):

  • W = 2
D年中日期別。某些平台不支援此樣式。此樣式可有一至三個字母。

以一年的第二天為例 (對支援此樣式的作業系統而言):

  • D = 2
  • DD = 02
  • DDD = 002
F行事曆月份中當天的週次。例如,如果格式化 10 月第三個星期一的日期時,此元素會顯示 "3"。此樣式只允許一個字母。

以七月的第二個星期三為例 (對支援此樣式的作業系統而言):

  • F = 2
aAM/PM 指示器。此樣式只允許一個字母,a 或 p。

範例:

  • a = AM, 午前
  • p = PM, 午後
h12 小時格式 [1 - 12] 的日中小時別。此樣式必須為一或二個字母。

範例:

  • h = 1
  • h = 12
  • hh = 01
H24 小時格式 [0 - 23] 的日中小時別。此樣式必須為一或二個字母。

範例:

  • H = 0
  • H = 23
  • HH = 00
K12 小時格式 [0 - 11] 的日中小時別。此樣式必須為一或二個字母。並非所有作業系統都支援此樣式。

範例 (對支援此樣式的作業系統而言):

  • K = 0
  • K = 11
  • KK = 00
k24 小時格式 [1 - 24] 的日中小時別。此樣式必須為一或二個字母。並非所有作業系統都支援此樣式。

範例 (對支援此樣式的作業系統而言):

  • k = 1
  • k = 24
  • kk = 01
m小時中的分鐘別 [0 - 59]。此樣式必須為一或二個字母。

範例:

  • m = 2
  • m = 59
  • mm = 02
s分鐘中的秒數別 [0 - 59]。此樣式必須為一或二個字母。

範例:

  • s = 2
  • s = 59
  • ss = 02
S毫秒。這個樣式必須為一到五個字母。數值會根據所用的字母數而四捨五入。當使用五個字元 (SSSSS) 時,它代表含小數的毫秒。

範例:

  • S = 2
  • SS = 24
  • SSS = 235
  • SSSS = 2350
  • SSSSS = 23500
z時區。不參照特定地區,但考慮標準或日光節約時間,將時區表示為字串。並非所有作業系統都支援此樣式。在不支援時區樣式的作業系統中,輸入樣式的字母會被取代為空字串。在支援此樣式的作業系統上,並非所有地區設定都具有已定義的字串。未定義的地區設定會退回當地語系化的 GMT 格式,如 GMT-08:00 或 GW-08:00

此時區樣式必須有一至四個字母,解譯如下:

  • 若樣式字母數為一到三,格式會被解譯為縮寫形式。
  • 若樣式字母數為四,格式會被解譯為完整名稱。

範例 (對支援此格式的作業系統而言):

  • z, zz, zzz = PDT
  • z, zz, zzz = PST
  • z, zz, zzz = GMT-0800
  • zzzz = 太平洋日光節約時間
  • zzzz = 太平洋標準時間
Z時區。以和 GMT 的偏移值表示時區。並非所有作業系統都支援此樣式。在不支援時區樣式的作業系統中,輸入樣式的字母會被取代為空字串。

此時區樣式必須有一至四個字母,解譯如下:

  • 若樣式字母數為一到三,格式會使用 RFC 822 格式。
  • 若樣式字母數為四,格式會使用當地語系化的 GMT 格式。對於無當地語系化 GMT 格式的地區設定,會退回非當地語系化 GMT 格式。

範例 (對支援此格式的作業系統而言):

  • Z, ZZ, ZZZ = -0800
  • ZZZZ = GMT-08:00, GW-08:00
v時區。不指特定地區或區分日光節約時間或標準時間的一般時區字串。並非所有作業系統都支援此樣式。在不支援時區樣式的作業系統中,輸入樣式的字母會被取代為空字串。在不支援此樣式的作業系統中,若無法使用當地語系化名稱,會提供後援字串。

此時區樣式必須有一或四個字母,解譯如下:

  • 若樣式字母數為一,格式會使用縮寫形式。
  • 若樣式字母數為四,格式會使用完整形式。

範例 (對支援此格式的作業系統而言):

  • v = PT
  • vvvv = 太平洋時間
'其他文字'此樣式字串中可包含文字和標點符號。但 a 到 z 與 A 到 Z 等字元保留為語法字元,在格式化字串中必須包含於單引號中。若要在結果字串中包含單引號,請在樣式字串中使用兩個單引號。兩個單引號可出現在樣式字串括住的部份裡面或外面。未成對的單引號會在字串結尾被截斷。

範例:

  • EEEE, MMM。d, yyyy 'at' h 'o''clock' a= Tuesday, Sept. 8, 2005 at 1 o'clock PM
  • yyyy年M月d日 = 2005年9月8日
  • mm''ss'' = 43'01'

當此方法被呼叫並成功完成時,lastOperationStatus 屬性會被設為:

  • LastOperationStatus.NO_ERROR

否則,lastOperationStatus 屬性會被設為 LastOperationStatus 類別中定義的常數之一。

參數

pattern:String


擲回值
TypeError — 若樣式參數為 null。

相關 API 元素

setDateTimeStyles

()方法 
public function setDateTimeStyles(dateStyle:String, timeStyle:String):void

語言版本: ActionScript 3.0
執行階段版本: Flash Player 10.1, AIR 2

設定此 DateTimeFormatter 實體的日期和時間樣式。日期和時間樣式可用來設定預先定義的日期和時間格式化樣式,地區設定會根據作業系統樣式而有所不同。此方法會取代使用 DateTimeFormatter() 建構函式或 setDateTimePattern() 方法所設定的樣式。同時會根據所設定的樣式,更新日期和時間樣式。

當此方法被呼叫並成功完成時,lastOperationStatus 屬性會被設為:

  • LastOperationStatus.NO_ERROR

否則,lastOperationStatus 屬性會被設為 LastOperationStatus 類別中定義的常數之一。

參數

dateStyle:String — 指定格式化日期時要使用的樣式。值會對應到 DateTimeStyle 類別所列舉的值之一:
  • DateTimeStyle.LONG
  • DateTimeStyle.MEDIUM
  • DateTimeStyle.SHORT
  • DateTimeStyle.NONE
 
timeStyle:String — 指定格式化時間時要使用的樣式。值會對應到 DateTimeStyle 類別所列舉的值之一:
  • DateTimeStyle.LONG
  • DateTimeStyle.MEDIUM
  • DateTimeStyle.SHORT
  • DateTimeStyle.NONE


擲回值
ArgumentError — 若 dateStyletimeStyle 參數非有效的 DateTimeStyle 常數。
 
TypeError — 若 dateStyletimeStyle 參數為 null。

相關 API 元素

DateTimeFormatter.1.as

以下範例顯示代表日期與時間值的字串如何根據地區設定而設為不同的格式。此範例的結果可能會根據作業系統和使用者偏好設定而有所不同。

本範例使用下列地區設定:英文 (美國)、法文 (法國)、西班牙文 (西班牙)。

此範例會為清單中的每一個地區設定執行以下動作:

  1. 使用預設樣式 (dateStyle 為 long,timeStyle 為 long) 建立 DateTimeFormatter 物件
  2. 使用預設的完整日期樣式,設定目前日期和時間的格式。
  3. 使用 DateTimeStyle.NONEDateTimeStyle.SHORT 常數,變更成只有時間的簡短日期樣式。
  4. 使用只有時間的簡短日期樣式,設定目前日期和時間的格式。
package {
    import flash.display.Sprite;
    import flash.globalization.DateTimeFormatter;
    import flash.globalization.DateTimeStyle;
    
    public class DateTimeFormatterExample extends Sprite
    {    
        private var localeList:Array = new Array("en-US", "fr-FR", "es-ES");
    
        public function DateTimeFormatterExample()
        {
            var date:Date = new Date();
            
            for each (var locale:String in localeList) {
                var dtf:DateTimeFormatter = new DateTimeFormatter(locale);
                trace('\n' + "LocaleID requested=" + dtf.requestedLocaleIDName 
                    + "; actual=" + dtf.actualLocaleIDName);
            
                var longDate:String = dtf.format(date);
                trace(longDate + " (" + dtf.getDateTimePattern() + ")");
            
                dtf.setDateTimeStyles(DateTimeStyle.NONE, DateTimeStyle.SHORT);
                var shortDate:String = dtf.format(date);
                trace(shortDate + " (" + dtf.getDateTimePattern() + ")");
            }        
        }
    }
}
DateTimeFormatter.2.as

以下範例顯示應用程式如何根據使用者選取的樣式來設定日期的格式。此範例的結果可能會根據作業系統和使用者偏好設定而有所不同。

此範例會為清單中的每一個地區設定執行以下動作:

  1. 建立三個輸入以及輸出文字欄位。
  2. 使用美國英文地區設定來建立 DateTimeFormatter 物件。
  3. 呼叫 configureTextField() 函數,它會設定文字欄位的位置和大小以及將偵聽程式加到 patternField 物件。
  4. 當使用者在 patternField 文字欄位輸入樣式後,textInputHandler 函數會使用該樣式來設定日期和時間的格式,並在輸出文字欄位中顯示結果和 lastOperationStatus 值。
 
package {  
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.globalization.DateTimeFormatter;
    import flash.text.*;
    
    public class DateTimePatternExample extends Sprite
    {    
        private var patternField:TextField = new TextField();
        private var resultField:TextField = new TextField();
        private var statusField:TextField = new TextField();
           private var date:Date = new Date();
         private var dtf:DateTimeFormatter = new DateTimeFormatter("en-US");           
         
        private function configureTextField():void
        {
            patternField.type = TextFieldType.INPUT;
            patternField.width = 300;
            patternField.height = 20;
            patternField.background = true;
            patternField.border = true;
            
            resultField.y = 40;
            resultField.width = 300;
            resultField.height = 20;
            
            statusField.y = 80;
            statusField.width = 300;
            statusField.height = 20;

            addChild(patternField);
            addChild(resultField);
            addChild(statusField);
            patternField.addEventListener(Event.CHANGE,textInputHandler);
        }

        private function textInputHandler(event:Event):void
        {                 
            dtf.setDateTimePattern(patternField.text);
            statusField.text = dtf.lastOperationStatus;
            resultField.text = dtf.format(date);
        }

        public function DateTimePatternExample()
        {
            configureTextField();    
        }
    }
}




[ X ]為什麼顯示英文?
「ActionScript 3.0 參考」的內容是以英文顯示

並非所有「ActionScript 3.0 參考」的內容都翻譯為所有語言。當語言元素未翻譯時,就會以英文顯示。例如,ga.controls.HelpBox 類別並沒有翻譯為任何語言。因此在參考的繁體中文版本中,ga.controls.HelpBox 類別就會以英文顯示。