Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-02-2009, 07:24 AM
Member
 
Join Date: Mar 2009
Posts: 35
Rep Power: 0
swati.jyoti is on a distinguished road
Question Locale with SimpleDateFormat
What does that mean when instantiating a SimpleDateFormat object,specify a locale?

Its good programming practice..Can u explain with an example..I am not getting the thing...
Bookmark Post in Technorati
Reply With Quote
  #2 (permalink)  
Old 07-02-2009, 10:44 AM
hardwired's Avatar
Senior Member
 
Join Date: Jul 2007
Posts: 1,577
Rep Power: 4
hardwired is on a distinguished road
Default
Code:
import java.text.*;
import java.util.*;

public class LocalDate {
    public static void main(String[] args) {
        String pattern = "hhmm ddMMMyyy";
        Locale[] locales = {
            Locale.CHINA, Locale.CHINESE, Locale.ITALY, Locale.ITALIAN,
            Locale.JAPAN, Locale.JAPANESE
        };
        for(int i = 0; i < locales.length; i++) {
            DateFormat df = new SimpleDateFormat(pattern, locales[i]);
            System.out.printf(" %s: %s%n",
                               locales[i].getDisplayName(),
                               df.format(new Date()));
        }
    }
}
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 07-02-2009, 10:46 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 7,523
Rep Power: 11
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Default
I'm not clear what you exactly talking about here. Seems to me is the following.

SimpleDateFormat class have a constructor as follows.

Code:
SimpleDateFormat(String pattern, Locale locale)
So I guess you have mess-up with Local object. Did you read the Java doc related to that? Here Locale object represent a specific geographical location. You can find around 20 Local fields in the Java doc, sorry I didn't remember exact figures here.

Is that what you are looking for?
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
Someone helped you? their helpful post.
Help:Forums FAQ|How To Ask Questions The Smart WayResources:The Java Tutorials|Glossary for Java|NetBeans IDE|Sun DownloadsWeb:WritOnceTips:Is your IDE the best?|Which Application Server?
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 07-02-2009, 01:01 PM
Member
 
Join Date: Mar 2009
Posts: 35
Rep Power: 0
swati.jyoti is on a distinguished road
Default
Ya this was the same thing i m looking for...

Thanks...
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 07-02-2009, 03:34 PM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 7,523
Rep Power: 11
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Default
You got a nice example from harwired as well.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
Someone helped you? their helpful post.
Help:Forums FAQ|How To Ask Questions The Smart WayResources:The Java Tutorials|Glossary for Java|NetBeans IDE|Sun DownloadsWeb:WritOnceTips:Is your IDE the best?|Which Application Server?
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to use SimpleDateFormat in J2ME Applications thirupathik CDC and Personal Profile 6 09-03-2009 12:47 PM
Using SimpleDateFormat Java Tip Java Tips 1 07-18-2008 09:33 AM
Locale example Java Tip Java Tips 0 01-29-2008 10:04 AM
How ro change the locale of JVM ravi.ks007@hotmail.com Advanced Java 2 12-26-2007 07:17 AM
Locale Java Tip Java Tips 0 11-16-2007 03:16 PM


All times are GMT +2. The time now is 07:19 AM.



VBulletin, Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org