패키지 | mx.formatters |
클래스 | public class DateFormatter |
상속 | DateFormatter Formatter Object |
하위 클래스 | ExpiryDateFormat |
언어 버전: | ActionScript 3.0 |
제품 버전: | Flex 3 |
런타임 버전: | Flash Player 9, AIR 1.1 |
Flex 4.5(으)로 시작하는 경우 이 클래스 대신 spark.formatters.DateTimeFormatter 클래스를 사용하는 것이 좋습니다. |
The DateFormatter class uses a format String to return a formatted date and time String from an input String or a Date object. You can create many variations easily, including international formats.
If an error occurs, an empty String is returned and a String describing
the error is saved to the error
property. The error
property can have one of the following values:
-
"Invalid value"
means a value that is not a Date object or a is not a recognized String representation of a date is passed to theformat()
method. (An empty argument is allowed.) -
"Invalid format"
means either theformatString
property is set to empty (""), or there is less than one pattern letter in theformatString
property.
The parseDateString()
method uses the mx.formatters.DateBase class
to define the localized string information required to convert
a date that is formatted as a String into a Date object.
You use the <mx:DateFormatter>
tag
to render date and time Strings from a Date object.
The <mx:DateFormatter>
tag
inherits all of the tag attributes of its superclass,
and adds the following tag attributes:
<mx:DateFormatter formatString="Y|M|D|A|E|H|J|K|L|N|S|Q" />
관련 API 요소
속성 | 정의 주체 | ||
---|---|---|---|
constructor : Object
지정된 객체 인스턴스의 클래스 객체 또는 생성자 함수에 대한 참조입니다. | Object | ||
error : String
Description saved by the formatter when an error occurs. | Formatter | ||
formatString : String
The mask pattern. | DateFormatter |
메서드 | 정의 주체 | ||
---|---|---|---|
Constructor. | DateFormatter | ||
[재정의]
Generates a date-formatted String from either a date-formatted String or a Date object. | DateFormatter | ||
지정된 속성이 객체에 정의되어 있는지 여부를 나타냅니다. | Object | ||
Object 클래스의 인스턴스가 매개 변수로 지정된 객체의 프로토타입 체인에 있는지 여부를 나타냅니다. | Object | ||
[정적]
Converts a date that is formatted as a String into a Date object. | DateFormatter | ||
지정된 속성이 존재하고 열거 가능한지 여부를 나타냅니다. | Object | ||
루프 작업에서 동적 속성을 사용할 수 있는지 여부를 설정합니다. | Object | ||
로캘별 규칙에 따라 서식이 지정된 이 객체의 문자열 표현을 반환합니다. | Object | ||
지정된 객체의 문자열 표현을 반환합니다. | Object | ||
지정된 객체의 프리미티브 값을 반환합니다. | Object |
formatString | 속성 |
formatString:String
언어 버전: | ActionScript 3.0 |
제품 버전: | Flex 3 |
런타임 버전: | Flash Player 9, AIR 1.1 |
The mask pattern.
You compose a pattern String using specific uppercase letters, for example: YYYY/MM.
The DateFormatter pattern String can contain other text in addition to pattern letters. To form a valid pattern String, you only need one pattern letter.
The following table describes the valid pattern letters:
Pattern letter | Description |
---|---|
Y | Year. If the number of pattern letters is two, the year is
truncated to two digits; otherwise, it appears as four digits.
The year can be zero-padded, as the third example shows in the
following set of examples:
|
M | Month in year. The format depends on the following criteria:
|
D | Day in month. While a single-letter pattern string for day is valid,
you typically use a two-letter pattern string.
Examples:
|
E | Day in week. The format depends on the following criteria:
|
A | am/pm indicator. |
J | Hour in day (0-23). |
H | Hour in day (1-24). |
K | Hour in am/pm (0-11). |
L | Hour in am/pm (1-12). |
N | Minute in hour.
Examples:
|
S | Second in minute.
Example:
|
Q | Millisecond in second
Example:
|
Other text | You can add other text into the pattern string to further
format the string. You can use punctuation, numbers,
and all lowercase letters. You should avoid uppercase letters
because they may be interpreted as pattern letters.
Example:
|
기본값: "MM/DD/YYYY".
구현
public function get formatString():String
public function set formatString(value:String):void
DateFormatter | () | 생성자 |
public function DateFormatter()
언어 버전: | ActionScript 3.0 |
제품 버전: | Flex 3 |
런타임 버전: | Flash Player 9, AIR 1.1 |
Constructor.
format | () | 메서드 |
override public function format(value:Object):String
언어 버전: | ActionScript 3.0 |
제품 버전: | Flex 3 |
런타임 버전: | Flash Player 9, AIR 1.1 |
Generates a date-formatted String from either a date-formatted String or a Date object.
The formatString
property
determines the format of the output String.
If value
cannot be formatted, return an empty String
and write a description of the error to the error
property.
매개 변수
value:Object — Date to format. This can be a Date object,
or a date-formatted String such as "Thursday, April 22, 2004".
|
String — Formatted String. Empty if an error occurs. A description
of the error condition is written to the error property.
|
parseDateString | () | 메서드 |
public static function parseDateString(str:String):Date
언어 버전: | ActionScript 3.0 |
제품 버전: | Flex 3 |
런타임 버전: | Flash Player 9, AIR 1.1 |
Converts a date that is formatted as a String into a Date object. Month and day names must match the names in mx.formatters.DateBase. The hour value in the String must be between 0 and 23, inclusive. The minutes and seconds value must be between 0 and 59, inclusive. The following example uses this method to create a Date object:
var myDate:Date = DateFormatter.parseDateString("2009-12-02 23:45:30");
매개 변수
str:String — Date that is formatted as a String.
|
Date — Date object.
|
관련 API 요소
<?xml version="1.0" encoding="utf-8"?> <!-- Simple example to demonstrate the DateFormatter. --> <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/mx"> <fx:Script> <![CDATA[ import mx.events.ValidationResultEvent; private var vResult:ValidationResultEvent; // Event handler to validate and format input. private function Format():void { vResult = dateVal.validate(); if (vResult.type == ValidationResultEvent.VALID) { formattedDate.text = dateFormatter.format(dob.text); } else { formattedDate.text = ""; } } ]]> </fx:Script> <fx:Declarations> <mx:DateFormatter id="dateFormatter" formatString="month: MM, day: DD, year: YYYY"/> <mx:DateValidator id="dateVal" source="{dob}" property="text" inputFormat="mm/dd/yyyy"/> </fx:Declarations> <s:Panel title="DateFormatter Example" width="75%" height="75%" horizontalCenter="0" verticalCenter="0"> <mx:Form left="10" right="10" top="10" bottom="10"> <mx:FormItem label="Enter date (mm/dd/yyyy):" width="100%"> <s:TextInput id="dob" text=""/> </mx:FormItem> <mx:FormItem label="Formatted date: " width="100%"> <s:TextInput id="formattedDate" text="" editable="false"/> </mx:FormItem> <mx:FormItem> <s:Button label="Validate and Format" click="Format();"/> </mx:FormItem> </mx:Form> </s:Panel> </s:Application>
Tue Jun 12 2018, 03:17 PM Z