Use getDateInstance to get the normal date format for that country. For example,
import java.text.DateFormat;
import java.util.Date;
public class DateFormatExample {
public static void main(String[] args) {
Date now = new Date();
DateFormat defaultDf = DateFormat.getDateInstance();
DateFormat shortDf = DateFormat.getDateInstance(DateFormat.SHORT);
DateFormat mediumDf = DateFormat.getDateInstance(DateFormat.MEDIUM);
DateFormat longDf = DateFormat.getDateInstance(DateFormat.LONG);
DateFormat fullDf = DateFormat.getDateInstance(DateFormat.FULL);
System.out.println(" 1. " + defaultDf.format(now));
System.out.println(" 2. " + shortDf.format(now));
System.out.println(" 3. " + mediumDf.format(now));
System.out.println(" 4. " + longDf.format(now));
System.out.println(" 5. " + fullDf.format(now));
}
}
The output is
1. Jun 20, 2008
2. 6/20/08
3. Jun 20, 2008
4. June 20, 2008
5. Friday, June 20, 2008
Use getTimeInstance to get the time format for that country. For example,
import java.text.DateFormat;
import java.util.Date;
public class DateFormatExample {
public static void main(String[] args) {
Date now = new Date();
DateFormat defaultDf = DateFormat.getTimeInstance();
DateFormat shortDf = DateFormat.getTimeInstance(DateFormat.SHORT);
DateFormat mediumDf = DateFormat.getTimeInstance(DateFormat.MEDIUM);
DateFormat longDf = DateFormat.getTimeInstance(DateFormat.LONG);
DateFormat fullDf = DateFormat.getTimeInstance(DateFormat.FULL);
System.out.println(" 1. " + defaultDf.format(now));
System.out.println(" 2. " + shortDf.format(now));
System.out.println(" 3. " + mediumDf.format(now));
System.out.println(" 4. " + longDf.format(now));
System.out.println(" 5. " + fullDf.format(now));
}
}
The output is
1. 10:09:12 PM
2. 10:09 PM
3. 10:09:12 PM
4. 10:09:12 PM EDT
5. 10:09:12 PM EDT
Use getDateTimeInstance to get a date and time format. For example,
import java.text.DateFormat;
import java.util.Date;
public class DateFormatExample {
public static void main(String[] args) {
Date now = new Date();
DateFormat defaultDf = DateFormat.getDateTimeInstance();
DateFormat shortDf = DateFormat.getDateTimeInstance(
DateFormat.SHORT, DateFormat.SHORT);
DateFormat mediumDf = DateFormat.getDateTimeInstance(
DateFormat.MEDIUM, DateFormat.SHORT);
DateFormat longDf = DateFormat.getDateTimeInstance(
DateFormat.LONG, DateFormat.SHORT);
DateFormat fullDf = DateFormat.getDateTimeInstance(
DateFormat.FULL, DateFormat.SHORT);
System.out.println(" 1. " + defaultDf.format(now));
System.out.println(" 2. " + shortDf.format(now));
System.out.println(" 3. " + mediumDf.format(now));
System.out.println(" 4. " + longDf.format(now));
System.out.println(" 5. " + fullDf.format(now));
System.out.println("============================");
shortDf = DateFormat.getDateTimeInstance(DateFormat.SHORT,
DateFormat.MEDIUM);
mediumDf = DateFormat.getDateTimeInstance(DateFormat.MEDIUM,
DateFormat.MEDIUM);
longDf = DateFormat.getDateTimeInstance(DateFormat.LONG,
DateFormat.MEDIUM);
fullDf = DateFormat.getDateTimeInstance(DateFormat.FULL,
DateFormat.MEDIUM);
System.out.println(" 6. " + shortDf.format(now));
System.out.println(" 7. " + mediumDf.format(now));
System.out.println(" 8. " + longDf.format(now));
System.out.println(" 9. " + fullDf.format(now));
System.out.println("============================");
shortDf = DateFormat.getDateTimeInstance(DateFormat.SHORT,
DateFormat.LONG);
mediumDf = DateFormat.getDateTimeInstance(DateFormat.MEDIUM,
DateFormat.LONG);
longDf = DateFormat.getDateTimeInstance(DateFormat.LONG,
DateFormat.LONG);
fullDf = DateFormat.getDateTimeInstance(DateFormat.FULL,
DateFormat.LONG);
System.out.println(" 10. " + shortDf.format(now));
System.out.println(" 11. " + mediumDf.format(now));
System.out.println(" 12. " + longDf.format(now));
System.out.println(" 13. " + fullDf.format(now));
System.out.println("============================");
shortDf = DateFormat.getDateTimeInstance(DateFormat.SHORT,
DateFormat.FULL);
mediumDf = DateFormat.getDateTimeInstance(DateFormat.MEDIUM,
DateFormat.FULL);
longDf = DateFormat.getDateTimeInstance(DateFormat.LONG,
DateFormat.FULL);
fullDf = DateFormat.getDateTimeInstance(DateFormat.FULL,
DateFormat.FULL);
System.out.println(" 14. " + shortDf.format(now));
System.out.println(" 15. " + mediumDf.format(now));
System.out.println(" 16. " + longDf.format(now));
System.out.println(" 17. " + fullDf.format(now));
}
}
The output is
1. Jun 21, 2008 9:30:41 PM
2. 6/21/08 9:30 PM
3. Jun 21, 2008 9:30 PM
4. June 21, 2008 9:30 PM
5. Saturday, June 21, 2008 9:30 PM
============================
6. 6/21/08 9:30:41 PM
7. Jun 21, 2008 9:30:41 PM
8. June 21, 2008 9:30:41 PM
9. Saturday, June 21, 2008 9:30:41 PM
============================
10. 6/21/08 9:30:41 PM EDT
11. Jun 21, 2008 9:30:41 PM EDT
12. June 21, 2008 9:30:41 PM EDT
13. Saturday, June 21, 2008 9:30:41 PM EDT
============================
14. 6/21/08 9:30:41 PM EDT
15. Jun 21, 2008 9:30:41 PM EDT
16. June 21, 2008 9:30:41 PM EDT
17. Saturday, June 21, 2008 9:30:41 PM EDT