Share on Google+Share on Google+

Date Class with multiple numeric parameter constructor

Advertisement
In this example we have created Date class object and pass multiple numeric parameters.

Date class with multiple numeric parameters to the Date() constructor example:-

In this example we have created Date class object and pass multiple numeric parameters as  the year, month, day, hour, minute, second, and millisecond, respectively, and returns a corresponding Date object. The date class object take time information of the midnight to the related date. This is the example of multiple numeric parameterized constructor of the date class.

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 currdate:Date = new Date(2010, 5, 1, 0, 0, 0, 0);

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

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

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

}

]]>

</fx:Script>

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

<mx:VBox>

<mx:HBox>

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

<mx:Text id="mytext"/>

</mx:HBox>

<mx:HBox>

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

<mx:Text id="mytext1"/>

</mx:HBox>

<mx:HBox>

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

<mx:Text id="mytext2"/>

</mx:HBox>

</mx:VBox>

</s:Panel>

</s:Application>

In this example we have pass values 2010 for year , 5 for month, 1 for day, 0's for hours, minutes, seconds, and milliseconds. Users note that the month value is starts 0 to11 so the numeric value 5 have corresponding month is June.

Output:-

Download this code

Advertisements

Posted on: June 2, 2010 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.