Date Class with Single String parameter constructor example


 

Date Class with Single String parameter constructor example

The Date class have a single string parametrized constructor.

The Date class have a single string parametrized constructor.

Date class with single string parameters to the Date() constructor example:-

The Date class have a single string parameterized constructor. If user pass a string parameter in the date class object, then it will convert that string in to date or time components after that return a corresponding Date object . The Date() constructor accepts a number of different string formats. User can see how to use this type of constructor for the Date class in this example.

Example:-

<?xml version="1.0" encoding="utf-8"?>

<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" creationComplete="init();">

<fx:Script>

<![CDATA[

public function init():void{

var nextDay:Date = new Date("Tue Jun 1 2010 05:30:00 PM");

mytext.text = (String)(nextDay.toDateString());

mytext1.text = (String)(nextDay.toLocaleTimeString());

mytext2.text = (String)(nextDay.toLocaleString());

}

]]>

</fx:Script>

<s:Panel width="335" height="130" title="Date Class Panel" backgroundColor="0xE0FFFF">

<mx:VBox>

<mx:HBox>

<mx:Label text="The Date :"/>

<mx:Text id="mytext"/>

</mx:HBox>

<mx:HBox>

<mx:Label text="The Time :"/>

<mx:Text id="mytext1"/>

</mx:HBox>

<mx:HBox>

<mx:Label text="The Date and Time :"/>

<mx:Text id="mytext2"/>

0

</mx:HBox>

</mx:VBox>

</s:Panel>

1

</s:Application>

In this example we have created a Date class object and pass a string parameter in this object to access the parameterized constructor of the Date class and return the date and time of the corresponding the passing parameter.

Output:-

2

Download this code

Ads