Saturday, February 27, 2016

SimpleDateFormat and DateFormat

SimpleDateFormat is a class used to format and parsing dates in a locale sensitive manner. It is used to format date into text and parse text into date.
SimpleDateFormat is extends DateFormat class which is an abstract class for date/time formatting subclasses and provides many class methods for obtaining date/time matters based on any given locale. package com.lea.oops;

import java.text.SimpleDateFormat;
import java.util.Date;

public class SimpleDateFormatExample {

    /**
     * @param args
     */
    public static void main(String[] args) {

        Date date = new Date();
       
        String str = date.toString();
        System.out.println(str);
       
        SimpleDateFormat dateFormat = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy");
        System.out.println(dateFormat.format(date));
    }

}

No comments: