Java DateFormat clone() Example

DateFormat class clone() method example. This example shows you how to use clone() method.


Syntax is : public Object clone()
This method create a clone object of specified DateFormat object.

Here is the code.
/**
 * @(#) CloneDateFormat.java
 * A class representing use of method clone() of DateFormat
class in java.text Package.
 * @Version  12-May-2008
 @author   Rose India Team
 */
import java.util.*;
import java.text.*;

class CloneDateFormat {

    public static void main(String[] args) {

        // Create new Date object that will be initialized to the current date.
        Date date = new Date();
        System.out.println("Date  by  Date  class    : " + date.toString());

        // Create new DateFormat object that will returns default date/time.
        DateFormat dateFormat = DateFormat.getInstance();
        String stringDate = dateFormat.format(date);
        System.out.println("Date by DateFormat class : " + stringDate);

        // clone method call for DateFormat object.
        DateFormat cloneObj = (DateFormat)dateFormat.clone();
        String strCloneDate = cloneObj.format(date);
        System.out.println("Date by  clone object    : " + strCloneDate);
    }
}

Output of the program.
 Date  by  Date  class    : Thu Jun 12 17:49:40 GMT+05:30 2008
Date by DateFormat class : 6/12/08 5:49 PM
Date by  clone object    : 6/12/08 5:49 PM

Post Comment
Name:
E-mail:
Contact no :
Comments:
  Refresh Image
Verify Image:
 
 
Your Comment's
 
 
 

HOME | COPYRIGHT | CONTACT US