Share on Google+Share on Google+

Date Class with Single String parameter constructor example

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.


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

<s:Application xmlns:fx=""


xmlns:mx="library://" creationComplete="init();">



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());




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



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

<mx:Text id="mytext"/>



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

<mx:Text id="mytext1"/>



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

<mx:Text id="mytext2"/>





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.


Download this code


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.


Advertisement null