Forcing YYYY in locale SHORT date format

Does anyone know how to force Java 1.2.2 to display the year in SHORT format as 4 digits without destroying the locale sensitivity of the application. Take the following line of code..
DateFormat.getDateInstance(DateFormat.SHORT).format(value);
That snippet returns a string formatted for the default locale. In the USA this means the year will be displayed as 'YY'. The question is how to force SHORT to 'YYYY'.
I know I can switch to SimpleDateFormat and supply my own pattern. but then locale sensitivity is lost. For example, I can specify that the pattern is MM/dd/YYYY but this means all locales will use this format. Is that correct? Or does applyLocalizedPattern() in Java somehow translate my hardcoded pattern in a localized pattern.

I would imagine that the idea is that the locale defines its own SHORT format, and if you want the locale's SHORT format, you don't get to customize it--the SHORT format is what it is.
I don't know of a good answer to your problem, but if nobody comes up with anything better, I have a suggestion for a kludgey workaround.
Get the format for SHORT, do a regexp replace of "YYYY" for "YY" (making sure you don't already have "YYYY"), then create a new SimpleDateFormat from that.
Not pretty I know, but if nothing more elegant comes up, then it may at least get you the behavior you want.

Similar Messages

  • Convert the date of string to datetime format 'MM/dd/yyyy' when the system date format is 'dd/MM/yyyy'.

    I need convert the date of string format 'MM/dd/yyyy' to datetime format 'MM/dd/yyyy' when the system date format is 'dd/MM/yyyy'.Since
    I need to search values based on date where my database datetime  is 'MM/dd/yyyy' format.

    In my opinion you should re-consider the assumption that the date picker returns a string. Maybe it is able to return a
    DateTime object directly instead of string. Then you will pass this value as a parameter of SQL query. This should work regardless of computer configuration.
    Otherwise, follow the previous string-based approaches.

  • Using different locale with date format

    Hi guys,
    I'm trying to print of the same date represented in its different locale but can't seem to get it right. I want the
    dates and times to be represented appropriately (e.g., ?Feb? should be represented as ?f?vr.? in a
    localized for France). I've also tried to use SimpleDateFormat but had no luck there either.
    Locale[] locales = { new Locale("fr", "FR"), new Locale("zh", "CN"),
                 new Locale("it", "IT") };
    for (int i = 0; i < locales.length; i++) {
                  //print date in the different locales
                  try {
                       changeLanuage(locales);
              }catch(IOException e) {
                   System.out.println("ERROR:");
              System.out.println()
    public void changeLanuage(Local loc)
    String dateString = "Sun Jan 27 01:56:00 GMT 2008"
    // Get the default MEDIUM/MEDIUM DateFormat
    String sdate = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM).format(new Date());
    System.out.println(sdate);
    try {
    Date date;
    date = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM,loc).parse(sdate);
    String output;
    output = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL,loc).format(date);
    outputStream.write(output);
    }catch(ParseException pe) {
    System .out.println("ERROR: for lanuage could not parse date in string \"" +
    dateString + "\"");
    pe.printStackTrace();
    Running the code, at the terminal i get the following output.Apr 3, 2008 5:00:03 PM
    ERROR: for lanuage could not parse date in string "Mon Jun 12 10:50:00 BST 2006"
    java.text.ParseException: Unparseable date: "Apr 3, 2008 5:00:03 PM"
         at java.text.DateFormat.parse(DateFormat.java:335)
         at readParser.changeLanuage(readParser.java:275)
         at readParser.main(readParser.java:412)
    If anyone can see what the problem is and how i can overcome it, i would greatly appreciate it if said so.
    Thanks a Lot                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

    okay i've attempted date --> format but this getting the same exception throw at run time.
    outputStream.write(present+" "+s.next()+"");
    String dateString = "Mon Jun 12 10:50:00 BST 2006"
    try {
         //parse with default format
          Date dtTmp = new SimpleDateFormat("MMM d, yyyy  H:mm:ss a",loc).parse(dateString);
          String strOutDt = new SimpleDateFormat("yyyy-MM-dd").format(dtTmp);
         outputStream.write(strOutDt+"DONE");
    }catch(ParseException pe) {
         System .out.println("ERROR: for lanuage could not parse date in string \"" +
         dateString + "\"");
         pe.printStackTrace();
    }Any suggestions/help would be great, thanks
    ERROR: for lanuage could not parse date in string "Mon Jun 12 10:50:00 BST 2006"
    java.text.ParseException: Unparseable date: "Mon Jun 12 10:50:00 BST 2006"
         at java.text.DateFormat.parse(DateFormat.java:335)
         at readParser.changeLanuage(readParser.java:261)
         at readParser.main(readParser.java:397)

  • How can I get the OS short date format?

    I want to get the format of OS computer in java.
    somthing that return to me:
    yyyy/MM/dd
    or
    MM/dd/yyyy
    og
    dd/MM/yyyy
    Thanks and have a nice weekend!

    DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT);
                   Date date = new Date();
                   System.out.println("The short date is : " + df.format(date));OR you can specify which format you want
    DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
                   Date date = new Date();
                   System.out.println("The short date is : " + df.format(date));Message was edited by:
    SomeoneElse

  • DateFormatContext - how to change default locale and date formatting?

    Hi,
    I need change default DateFormat e.g. from SHORT to MEDIUM, but I want to change default format for all pages, because I use for all bc4j:table automatic generation oc columns. Does anybody how to do it?
    I tried this:
    public void requestStarted(BajaContext context)
    Locale locale = new Locale("cs", "", "");
    MutableLocaleContext mContext = new MutableLocaleContext(locale);
    MutableDateFormatContext dfc = new MutableDateFormatContext(mContext.getDateFormatContext());
    But "dfc" doesn't have any set methods, where I could assign my formatter to the context:
    SimpleDateFormat DtFrmt = new SimpleDateFormat();
    // this I want to get to dfc
    dfc <== DtFrmt.getDateInstance(DtFrmt.MEDIUM, locale);
    Vl.

    I don't think this is possible. The dateField has a default validator on it which determines the date format, changing the dateFormatContext won't change the validator.

  • Bermuda Short (Date Format)

    I live in Bermuda.  We use a D/M/Y date format as in the UK, but  we use (123) 456-7890 for telephone numbers as in North America.  I used to use Canada as my region setting to satisfy this combination.  In iOS 5, selecting Canada now gives me YYYY-MM-DD dates.  I was happy to then find that Bermuda is actually now an option in the Region Format list (take that, Bahamas and Barbuda!), but selecting Bermuda erroneously gives me  the U.S. M/D/Y format.  It seems the only way way to get my desired D/M/Y is to choose a European, African, or Asian country, but then my Address Book phone numbers are nearly unrecognizable.
    Is there a d/m/y, (123) 456-7890 option in the Region Format list (I haven't tried them all)?
    or
    is there a way to customize these settings?
    or
    how do I let Apple know they are using the wrong date format for Bermuda?

    well you could do something like this.
    String year = "02";// you said you are parsing this out...
    year = "20"+year;
    int yearAsInt = Integer.parseInt(year);but most likely the better way is to use date from string formatting tool already available http://java.sun.com/j2se/1.4/docs/api/java/text/SimpleDateFormat.html

  • Short date format option not working?

    I have a date inserted dynamically in an ASP page, and have the DW8 behavior set to 1/17/00 format, which edits the variable to be this:
    <%= DoDateTime((Recordset1.Fields.Item("EventDate").Value), 2, 1033) %>
    but when I view it on the page, it still shows 10/10/2010 instead of 10/10/10 ... anyone able to tell me why?

    Hi Sankha,
    Please refer the links below:
    http://scn.sap.com/thread/1659463
    http://scn.sap.com/thread/1533443
    Regards,
    Manoj

  • [11g] Date format when printing dashboard prompt

    Hello,
    i have a dashboard prompt with a between condition on a date format. When i display it on the dashboard, the format is perfect dd.mm.yyyy. But when i want to print the dashboard, the format is shown as yyyy-mm-dd. On the forum i found a hint about the localedefinitions.xml (Printer-friendly date format But there, the definition is ok
    <property name="dateShortFormat">dd.MM.yyyy</property> // default short date format for locale
    So, how can i change the format to dd.mm.yyyy when printing the dashboard. Any advice?
    Thanks
    Martin

    Davison,
       Its not possible using user settings. All you would need to do is copy the SAP SCRIPTForm  program(You can keep the Print program as such) and set date mask as required in SAP script text editor using command
    /: SET DATE MASK = 'MMMM DD, YYYY'
    Now the date variable value written out on the screen would be
    &DATE& -> JAN  01, 2010 
    You could revert to standard settings using command
    /: SET DATE MASK = ' '
    Regards
    Narasimhan

  • Changing date format in locale

    Hi Experts,
    Date, currency format and so on depends on locale. If locale changes formats change as well.
    But is possible to change these formats in locale itself (change, for example, short date format in locale en_US to dd/mm/yyyy instead of mm/dd/yyyy)?
    Best Regards
    Price Young

    Hi Price
    The date format is user dependent. It may vary from user to user depending upon the settings applied at the time of user creation. This can however be changed from transaction SU01 ( defaults tab).
    Also please check the following link:
    http://help.sap.com/javadocs/nwce/current/wdr/com/sap/tc/webdynpro/services/sal/localization/api/IWDResourceHandler.html
    and
    http://help.sap.com/javadocs/MDM/SP06P2/com/sap/mdm/valuetypes/format/MdmDateTimeFormatInfo.html
    I hope this helps
    Regards
    Chen

  • BEX: Changing date format from 'mm/dd/yyyy' to 'mon/yyyy'

    Happy Friday! I need to change the date format in my BEX query from a regular date format (dd/mm/yyyy) to display as 'JUN/2008'. Please note that I dont want to modify the date field but just need to display it month and year format in the bex query. Would truly appreciate a complete answer.
    Thanks

    Hi
    Check the first thread
    Hope this will solve your problem.
    How to change Date format in Bex to DD/MM/YYYY
    Check ur Windows or Excel settings. Try changing it in Control Panel->Regional Options->Date->Short Date format.
    change it in Control Panel->Regional Options->Date->Short Date format.
    Changing Date format in BEx & Web Application
    I Need to change Date Format in BEx report
    Regards
    M.A
    Edited by: M.A on Jun 27, 2008 10:12 PM

  • How to get the date format yyyy-mm-dd?

    Hi,
    I have an iphone (3.1.2) and would like to use the date format yyyy-mm-dd (international date format). Is the possible? If yes, how?
    Cheers

    I know of no other way to set the date format other than what I mentioned in my previous post. There are third party apps that will do what you want in the app. store, but they are not permitted to access the underlining software.

  • How to keep date format as dd/mm/yyyy in Agentry independent of backend value format?

    I am using Agentry 6.0.38.1 android client and 6.0.32 plugin.
    I want to keep date format as dd/mm/yyyy in Agentry independent of backend value date format.
    How can I do it?
    Regards
    -Prit

    Jason/Sravanthi
    When I log in with 6.0.38.1 android client, I get date format in dd/mm/yyyy independent of device date format (I checked by changing device date format) and when I log in with 6.0.30.x android client, I get date format in mm/dd/yyyy independent of device date format for the same export to same connection.
    Don't know why this is happening.
    Sravanthi,
    The solution you suggested didnt work
    Regards
    Prit

  • Change Date Format in Calendar prompt

    Hi All,
    I am on 11.1.1.5 and the calendar prompt on selection of date/typing of date defaults to MM/dd/yyyy but, the requirement is to make it to default to MM/dd/yy. I have made 3 changes to the localedefinitions.xml file (dateSeparator,dateShortFormat,dateOrder) and they look like below
    <property name="dateSeparator">/</property> // separator to use between fields in short date formats
    <property name="dateShortFormat">MM/dd/yy</property> // default short date format for locale
    <property name="dateOrder">mdy</property> // preferred order of date fields for input
    But I still dont see a change in the format of the Calendar prompt. Do I need to change something else too?

    I checked under the My Account the locale is set to English and I have the following in the file but still when I select in the prompt the date format is MM/dd/yyyy instead of MM/dd/yy
    <localeDefinition name="en"> <!-- english base -->
    <property name="localeDisplayMessage">kmsgLanguageName_en</property>
    <property name="defaultLanguage">en</property>
    <property name="characterSetList">locale:en</property>
    <property name="listSeparator">,</property>
    <property name="decimalSeparator">.</property>
    <property name="thousandsSeparator">,</property>
    <property name="dateSeparator">/</property>
    <property name="timeSeparator">:</property>
    <property name="am">AM</property>
    <property name="pm">PM</property>
    <property name="timeFormat">h:mm:ss tt</property>
    <property name="dateShortFormat">MM/dd/yy</property>
    <property name="dateLongFormat">dddd, MMMM dd, yyyy</property>
    <property name="negativeNumberTemplate">-#</property>
    <property name="collationImplementation">win:0409</property>
    <property name="dateOrder">mdy</property>

  • Date Format  changes in  the Reporting side..

    Hi friends,
    I have one date field that is Keyfigure (not a Time charecterstic) ...now i want to display date in DD- MON - YYYY format... but up to modelling side my date format is DD.MM.YYYY.....
    i dont want to change in modelling side.. because.. this required format is needed only for some querys ...
    so, can any one suggest me is there any chance to get the date format in the reporting side like this..(27-JAN-2007) ..
    helpful answers will be appriciated..
    Thanks
    Babu

    Hi Babu,
    If the format is required in the Bex analyser then its system dependent setting .
    Control panel - > Regional & language options -> Regional options -> Customize -> Date -> Short Date format -> DD-MMM-YYYY(Change) .
    Do not forget to log off and re-login into bex,execute queries and see the output.
    Hope that helps.
    Regards
    Mr Kapadia
    Assigning points is the way to say thanks in SDN.

  • How do i change the date format on an email?

    When my emails load the date shows as mm/dd/yyyy as this is not a format i use how do i change it to dd/mm/yyyy ?
    I had to reinstall Thunderbird and the date problem has just started from the reinstall.
    Thank you for your help.

    TB uses the short date format as set in your OS control panel, e.g. in Windows, Region and Language. There is also an add-on:
    https://addons.mozilla.org/en-us/thunderbird/addon/configdate/
    http://kb.mozillazine.org/Date_display_format

Maybe you are looking for

  • Possible bug in iTunes 10.6 - keeps re-syncing songs

    I have several hundred MP3s of very old songs from the 1910s and 1920s which sync to my iPod without problems.  When I acquired an iPhone 3GS with more limited capacity, I set iTunes to "convert higher bitrate songs to 128Kbps AAC".  This worked fine

  • Camera RAW changes not staying in Bridge/Photoshop

    Hi all, I've started having trouble with changes in Camera RAW not sticking once they're closed. I've got the XMP files, and Bridge shows the little icon to show it's been changed, but the changes aren't staying. I've tried clearing the cache, restar

  • Insert or Update a target with no constraints

    I am trying to figure out how to do an insert/update on a target table which doesn't have a constraint? In other words how to define a condition on this target table attribute to achieve this? please advice. ~Prabha

  • Css layout fix

    I suspect it is imbalanced div tags that is causing the layout issue the following webpage is experiencing. http://www.canchair.com/ While the ph.416.787.1709 etc information is listed to the right of the "quickship!" image, it is really supposed to

  • Accessing indicator properties when in an array of clusters

    I have a cluster with a numeric, boolean and string indicator (total of 3 indicators). This cluster is in an array with 5 rows. How do I set (for example) the  blinking property of the boolean in the 3rd row to true? Solved! Go to Solution.