Results 1 to 3 of 3
  1. #1
    hemanthjava is offline Member
    Join Date
    Dec 2007
    Posts
    22
    Rep Power
    0

    Default Java Locale Date Display Diff Format Prob

    I have written the below program to take the System Locale Language and the System Locale Country. Then Created the Locale Object and used it to format the Input Date to the Date of the Locale of the Client System. But there seems to be a difference in the formats displayed by the below Java Program as opposed to what is shown in my regional Settings as shown in the Screen shot.

    Java Code:
    import java.text.DateFormat;
    import java.text.ParseException;
    import java.text.SimpleDateFormat;
    import java.util.Locale;
    
    public class DateUtilEx {
    
    	public static void main(String args[]) {
    		String dateInGermanFormat = "27.02.2009"; // Input Date in German Date Format
    
    		String userLang = System.getProperty("user.language");
    		String userCountry = System.getProperty("user.country");
    
    		System.out.println("User Language : " + userLang + "\t"
    										+ "userCountry : " + userCountry);
    		Locale locale = new Locale(userLang, userCountry);
    
    		DateFormat localeFormatter = DateFormat.getDateInstance(
    										DateFormat.SHORT, locale);
    		SimpleDateFormat germanFormatter = new SimpleDateFormat("dd.MM.yyyy");
    		try {
    			System.out.println(localeFormatter.format(germanFormatter
    												.parse(dateInGermanFormat)));
    		} catch (ParseException e) {
    			e.printStackTrace();
    		}
    	}
    }
    Output
    User Language : en userCountry : US
    2/27/09

    What I see in the Regional Settings (in the Screenshot) - Short Date: 02/27/2009

    The year part is just 2 digits in the Java Program. Can you help me with this?
    Attached Thumbnails Attached Thumbnails Java Locale Date Display Diff Format Prob-regional-settings.jpg  

  2. #2
    hemanthjava is offline Member
    Join Date
    Dec 2007
    Posts
    22
    Rep Power
    0

    Default

    Can anybody help regarding this problem.

  3. #3
    serjant's Avatar
    serjant is offline Senior Member
    Join Date
    Jun 2008
    Location
    Ukraine,Zaporozhye
    Posts
    487
    Rep Power
    7

    Default

    Java Code:
    DateFormat localeFormatter = DateFormat.getDateInstance(DateFormat.MEDIUM, locale);

Similar Threads

  1. Date Format
    By learnspring in forum New To Java
    Replies: 1
    Last Post: 11-16-2008, 06:16 PM
  2. Simple Date Format
    By arimakidd in forum Java Applets
    Replies: 1
    Last Post: 09-29-2008, 05:46 AM
  3. How to format the date in particular pattern
    By Java Tip in forum java.text
    Replies: 0
    Last Post: 04-04-2008, 03:35 PM
  4. How to format the date in particular pattern
    By JavaBean in forum Java Tip
    Replies: 0
    Last Post: 10-04-2007, 10:28 PM
  5. Date format display in CSV file after exporting
    By latha in forum Advanced Java
    Replies: 0
    Last Post: 08-03-2007, 09:09 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •