Java SimpleDateFormat clone() Example

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


Syntax is : public Object clone()
This method creates a copy of this SimpleDateFormat. This also clones the format's date format symbols.

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

class CloneSimpleDateFormat {

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

        // Create new SimpleDateFormat object that returns default pattern.
        sdf = new SimpleDateFormat();
        String dateFormat = sdf.format(date);
        System.out.println("Date by SimpleDateFormat class : " + dateFormat);

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

Output of the program.
Date  by  Date  class          : Fri Jun 13 18:56:31 GMT+05:30 2008
Date by SimpleDateFormat class : 6/13/08 6:56 PM
Date by  clone object          : 6/13/08 6:56 PM

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

HOME | COPYRIGHT | CONTACT US