Hi all,
I have a string that contains different numbers that i have broken in different substring and appended as dd/mm/yyyy which denotes a date.
suppose i have a string s=" jan 06,2005"
and i have broken it to sub string jan , 06, 2005.
now i want to give this substring such as jan, 06, 2005 as input and i want to get date according to the geography.
is there any class that we can use so that it can be passed as an input and output will be geographic specific.
suppose we can pass the substring jan , 06,2005 or like dd/mm/yyyy(06/01/2005) but if the geographic area is USA then it will return the string in mm/dd/yyyy(01/06/2005) format.
please send me the code .
I am sending the code what i have below but not getting the desired output.
import java.util.*;
import java.text.*;
public class DateFormating {
static public void displayDate(Locale currentLocale) {
// string anotherday i want to send and the desired output will be according to the geographic area.
String anotherday="jan 05,2005";
Date today;
String result;
SimpleDateFormat formatter;
formatter = new SimpleDateFormat("dd.MM.yy", currentLocale);
today = new Date(anotherday);
result = formatter.format(today);
System.out.println("Locale: " + currentLocale.toString());
System.out.println("Result: " + result);
}
static public void displayPattern(String pattern, Locale currentLocale) {
Date today;
SimpleDateFormat formatter;
String output;
formatter = new SimpleDateFormat(pattern, currentLocale);
today = new Date();
output = formatter.format(today);
System.out.println(pattern + " " + output);
}
static public void main(String[] args) {
Locale[] locales = {
new Locale("fr","FR"),
new Locale("de","DE"),
new Locale("en","IND")
};
for (int i = 0; i < locales.length; i++) {
displayDate(locales[i]);
System.out.println();
}
String[] patterns = {
"dd/MM/yy",
"dd-MM-yy",
"MM/dd/yy",
"MM/dd/yyyy",
"yyyy/mm/dd"
};
for (int k = 0; k < patterns.length; k++) {
//changed the content with in Locale from "en","US" to "en","IND"
displayPattern(patterns[k], new Locale("en","IND"));
System.out.println();
}
System.out.println();
}
}
With Regards
sanjib