Java: How to format dates using Date and Calendar objects

import java.text.DateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;
public class FormatDate
{
  public sta

Java: How to format dates using  Date and Calendar objects
{filelink=5531}

import java.text.DateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;
public class FormatDate
{
  public static void main(String[] arg) {
    Locale f_fr = new Locale("fr", "FR"), f_us=new Locale("en", "US"), f_es = new Locale("es", "ES");
    Calendar c = Calendar.getInstance();
    c.set(1954, 03, 15);
    Date date = c.getTime();
    DateFormat fd_fr = DateFormat.getDateTimeInstance(DateFormat.MEDIUM,
        DateFormat.MEDIUM, f_fr)
    , fd_us = DateFormat.getDateTimeInstance(
        DateFormat.MEDIUM, DateFormat.MEDIUM, f_us)
    , fd_es = DateFormat.getDateTimeInstance(
        DateFormat.MEDIUM, DateFormat.MEDIUM, f_es);
    System.out.println("French Format: " + fd_fr.format(date));
    System.out.println("US English Format: " + fd_us.format(date));
    System.out.println("Spanish Format: " + fd_es.format(date));
  }
}

Be the first to leave a comment. Don’t be shy.

Join the Discussion

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>