Friday, September 27, 2013

Example of using SimpleDateFormat

SimpleDateFormat is a concrete class for formatting and parsing dates in a locale-sensitive manner. It allows for formatting (date -> text), parsing (text -> date), and normalization. It allows you to start by choosing any user-defined patterns for date-time formatting.

Example:
Example of using SimpleDateFormat
Example of using SimpleDateFormat

package java_time;

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

/**
 * @web http://java-buddy.blogspot.com/
 */
public class Java_Time {

    public static void main(String[] args) {

        Calendar now = Calendar.getInstance();
        Date nowDate = now.getTime();
        System.out.println(nowDate);
        
        SimpleDateFormat format;
        String formattedString;
        
        format = new SimpleDateFormat("yyyy-MM-dd kk:mm:ss");
        formattedString = format.format(nowDate);
        System.out.println(formattedString);
        
        format = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss(a)");
        formattedString = format.format(nowDate);
        System.out.println(formattedString);

    }
}


No comments:

Post a Comment