Formatter.format() difficulties

I am having troubles formating output. I am using JavaTM 2 Platform Standard Edition 5.0 API Specification and Java 1.5.0.
In the API there is a class called formatter that allows for you to format output by giving it arguments. Below is an exact copy of a portion of the example in the java API.
public class format {
     public static void main(String[] args) {
          StringBuilder sb = new StringBuilder();
             // Send all output to the Appendable object sb
             Formatter formatter = new Formatter(sb, Locale.US);
             // Explicit argument indices may be used to re-order output.
             formatter.format("%4$2s %3$2s %2$2s %1$2s", "a", "b", "c", "d");
             // -> " d  c  b  a"
}However when I try to compile it, It does not work and spits out the following.
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
The method format(String, Object[]) in the type Formatter is not applicable for the arguments (String, String, String, String, String)
at format.main(format.java:25)
What am I doing wrong?
Thanks

Yes it works.
But try as I suggest
javac -version.
I am pretty sure you ar using not the 1.5 compiler.
java version "1.5.0_02"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_02-b09)
Java HotSpot(TM) Client VM (build 1.5.0_02-b09, mixed mode, sharing)The java version itself is not of interest during compiling

Similar Messages

  • Java.util.Formatter format string for week of year?

    What is strange in the Formatter API, regarding dates, is that there is no format string to display week of year. To display day of year e.g. you can use:
    String.format(�%tj�),Calendar.getInstance())but what is the string for week of year?
    String.format(�%tw�),Calendar.getInstance())doesn�t work.
    Any ideas, or did I overlooked the API?

    I �m using
    String.format(�%tx�),Calendar.getInstance())everywhere in my code where x is any of the other (e.g. j, d etc.). Why use different way for this? How come Sun did�t add e.g. a w in the API to display the week of year as it does for day of year?

  • Get current date in mm/dd/yyyy format

    Need to get todays date in the format mm/dd/yyyy and store it in a database by using JDBC API ..how to convert Date given by Date() to the format mmdd/yyyy .The column type of the table whr date has to be inserted is of Type Date/Time (Microsoft Access)..
    Plz help me out ..plzzz..

    public static byte TIME_ONLY = 1;
    public static byte DATE_ONLY = 2;
    public static byte DATE_ALL = 3;
    public static String getCurrentDateTime(byte format, String dateFormatPattern) {
         String[] stringArray;
            String sDate;
         Date today;
         SimpleDateFormat formatter;
         formatter = new SimpleDateFormat(dateFormatPattern);
         today = new Date();
         sDate = formatter.format(today);
         if (format != DATE_ALL) {
              stringArray = sDate.split(" ");
              if (format == DATE_ONLY) {
                   sDate = stringArray[0].trim();
              } else {
                   sDate = stringArray[1].trim();
            return sDate;
    }

  • How to do formatting of messageStyleText in a table for each row

    Hello one and all,
    We have a requirement that the values displayed in figures must have a formatting same as we do in SQL
    for example : select TO_CHAR(4555.95 , '999,999,999.99') from dual
    OUTPUT will be 4,555.95
    Now i want to do the formatting for the messageStyleText which i have created as follows:
    Header
    Table
    messageStyleText
    The code that i am writing is as follows :
    public void processFormRequest(OAPageContext pageContext, OAWebBean webBean)
    super.processFormRequest(pageContext, webBean);
    //Call the AM by using create object, this object created only for FirstPG_AMImpl use
    FirstPG_AMImpl am =(FirstPG_AMImpl)pageContext.getApplicationModule(webBean);
    //Calling view object vo method when Go button is clicked.
    if (pageContext.getParameter("go")!=null)
    Object [] returnVa = (Object[]) am.payslipsummary(pageContext);
    OAMessageStyledTextBean earbean =(OAMessageStyledTextBean) webBean.findIndexedChildRecursive("inputValue");
    earbean.setValue(pageContext, returnVa[0]);
    when the query executes it displays 3 Rows in the table.
    Now, the formatting happens only for the first row displayed in my table. how to allow formatting to happen for all the rows???
    NOTE: the formatting code is in my AMImpl
    public Object[] payslipsummary(OAPageContext pageContext)
    Object [] strValue = new Object[10];
    NumberFormat numberFormat = NumberFormat.getInstance();
    numberFormat.setMinimumFractionDigits(2);
    numberFormat.setMaximumFractionDigits(2);
    numberFormat.setMinimumIntegerDigits(3);
    numberFormat.setMaximumIntegerDigits(20);
    return strValue;
    pls help!
    Brgds,
    Jenny

    Hi,
    To for the specific column value of all rows of table, please loop through the underlying VO of that table
    OAViewObject vo = (OAViewObject)am.findViewObject("View Object");
    if (vo != null) {
    Row TotalLinesVOrows[] = vo.getAllRowsInRange();
    RowSetIterator rowsetitr[] = vo.getRowSetIterators();
    if (vo.getRowCount() > 0) {
    rowsetitr[0].setRangeStart(0);
    rowsetitr[0].setRangeSize((int)vo.getRowCount());
    for (int count = 0; count < vo.getRowCount(); count++) {
    row = rowsetitr[0].getRowAtRangeIndex(count);
    Object value= row.getAttribute("ViewAttributename");
    Double fomattedValue=getFormatCurrency(value)
    row.setAttribute("ViewAttributename", fomattedValue);
    public String getUSFormatCurrency(double value)
    Locale locales = Locale.US ;
    DecimalFormat formatter = (DecimalFormat)
    NumberFormat.getCurrencyInstance(locales);
    String formattedCurrency = formatter.format(value);
    return formattedCurrency;
    Thanks
    Pratap

  • Current date in JSP in specific format....

    I want to view the current date on a JSP in the format YYYY-MM-DD
    I know how to get the current date
    <%= new Date()%>
    But how can I get the current date in the format specified above.
    Any help please??

    Thanx leo_pruna! I got the answer and here it is for anyone whose interested.
    import 'java.util.*, java.text.*'
    <%
    Date today;
    String output;
    SimpleDateFormat formatter;
    formatter = new SimpleDateFormat("yyyy-MM-dd");
    today = new Date();
    output = formatter.format(today);
    %>
    And show it anywhere on your page like this...
    <%= output%>

  • Mapping issue in Date Format

    Hi Experts,
    I have a mapping problem in my object.
    I have two filelds coming from the Control record of an IDoc CREDAT and CRETIM. Now, I need to concate them and put them in a target field DateandTimeCreated in the format: YYYYMMDDHHMMSS
    Is their an UDF or message mapping for this. Messge mapping will be better for me.DateTrans will work over here??
    Please reply.
    Thanks and regards,
    Aniruddha

    Sample UDF code:
    Execution Type:  Single Values
    Date UDF
    a)if your input date field declared as string then,
    public String dateValue(String value,  Container container) throws StreamTransformationException{
    String input =value;
    String strDate ="";
    if (input !=null)
    Date date1 = new java.util.Date(Long.parseLong(input));
    SimpleDateFormat  formatter = new SimpleDateFormat("yyyyMMdd");
    strDate = formatter.format(date1);
    return strDate;
    Time UDF
    a) if your input time field declared as string then,
    public String timeValue(String value,  Container container) throws StreamTransformationException{
    String input = value;
    String strTime="";
    if (input !=null)
    Date date = new java.util.Date(Long.parseLong(input));
    SimpleDateFormat  formatter = new SimpleDateFormat("HHmmss");
    strDate = formatter.format(date);
    return strTime;
    Note: include import statement
    import java.text.*
    If you have question, let us know. This code will work for sure.

  • Put java.sql.Date in correct format

    I need to put java.sql.Date in correct format to query an Oracle database.
    Here is my code:
            SimpleDateFormat formatter = new SimpleDateFormat("dd-MMM-yy");
            java.util.Date dateChosen = jXDatePicker1.getDate();
            String strDate = formatter.format(dateChosen);
            System.out.println("Date Chosen: " + strDate); // output is: 11-Feb-00
            java.util.Date parserDate = null;      
            try {
                parserDate = formatter.parse(strDate);
            } catch (ParseException re) {
                System.err.println("Exception caught: " + re.getMessage());
            // create java.sql.Date object
                java.sql.Date oraDate = new java.sql.Date(parserDate.getTime());
            System.out.println(oraDate);  // date is in this format: 2000-02-11
            System.out.println("formatted oraDate: " + formatter.format( oraDate ) ); // no good, stringIf I use formatter.format( oraDate ) I get the correct format (11-Feb-00) BUT it is no longer a sql Date, it is a String which can't be use.
    I have looked at the API and many other forum threads on this, any help would be greatly appreciated!

    In the class with the PreparedStatement, I pass the date like this:
    public class report extends javax.swing.JDialog {
         java.sql.Date newDate;
        public report(java.sql.Date passedOraDate, String passedtxtDate) {
            super();
            initComponents();
            setTitle("Report");
            setModal(true);
            newDate = passedOraDate;
            statusLabel.setText(passedtxtDate);
            System.out.println("passedtxtDate: " +passedtxtDate);       
            System.out.println("newDate: " +newDate);      
        }Here is the code that uses the actual PreparedStatement:
            try {
                // In my actual code I have all columns listed in query
                String query = "SELECT * FROM report WHERE repdate = ?";
                ps = conn.prepareStatement(query); // create a statement
                           ps.setDate(1, newDate); // set input parameter
                rs = ps.executeQuery();
                // extract data from the ResultSet
                ResultSetMetaData md = rs.getMetaData();
                int columns = md.getColumnCount();This is greatly edited to show relevant code!

  • Need help - Date format in es Tag / LoadedData

    hi,
    I have one Date attribute called 'EXPIRATION_DATE' in DOCUMENT table.
    I mapped this column entry in 'application-config.xml' as jdbc.column.EXPIRATION_DATE=ExpirationDate;
    And when I am trying to get this value in JSP,within '<es:forEachInArray>' tag
    scope, using the syntax below
    <%
    String strDate = (String)doc.getProperty("LodedDate","ExpirationDate");
    %>
    I am getting different formatted results in different environments
    Like , when I executed this in windows ,
    I got the resulted string as "Mon Jul 07 00:00:00 EDT 2003" , which can be converted
    to 'Date' type
    using <% Date exp_date = new Date(strDate); %> which solves my problem.
    But , when I executed same code to UNIX ,
    I got the resulted string as "2009-02-01 00:00:00.0" , which is not convertible
    to 'Date' format.
    I got the following exception , when I try to convert this resulted String to
    date format like.
    <% Date exp_date = new Date(strDate); %>
    java.lang.IllegalArgumentException
    at java.util.Date.parse(Date.java:585)
    at java.util.Date.<init>(Date.java:267)
    Finally , I need to convert the resulted string to "MMM dd, yyyy" (Feb 22, 2000)format.
    If not above method , what is the best way to get the resulted value in this "MMM
    dd, yyyy" format.
    /***** My Sample code ********/
    <es:forEachInArray array="<%=BankerMsgs%>" id="doc" type="Content" >
    <%String strDate = "";
         strDate = (String)doc.getProperty("LodedDate","ExpirationDate");     //strDate =
    "Mon Jul 07 00:00:00 EDT 2003"; // Windows
         //strDate = "2003-07-07 00:00:00.0"; // UNIX
         out.println("Original Date is :" + strDate); // In windows env I got this formatted
    result 'Mon Jul 07 00:00:00 EDT 2003' and In UNIX I got the string as '2003-07-07
    00:00:00.0'
         SimpleDateFormat formatter = new SimpleDateFormat ("MMM dd, yyyy");
         Date strDate12 = new Date(strDate);
         String strExpDate = "";
         try
              strExpDate = formatter.format(strDate12);
              out.println("Formatted Date is :" + strExpDate); // in windows I got correct
    result as 'Jul 07, 2003' and in UNIX java.lang.IllegalArgumentException
         catch(Exception e) {}
    %>     
    </es:forEachInArray>
    Any help will be much appreciated.
    thanks
    -Amar Purumandla

    hi,
    I have one Date attribute called 'EXPIRATION_DATE' in DOCUMENT table.
    I mapped this column entry in 'application-config.xml' as jdbc.column.EXPIRATION_DATE=ExpirationDate;
    And when I am trying to get this value in JSP,within '<es:forEachInArray>' tag
    scope, using the syntax below
    <%
    String strDate = (String)doc.getProperty("LodedDate","ExpirationDate");
    %>
    I am getting different formatted results in different environments
    Like , when I executed this in windows ,
    I got the resulted string as "Mon Jul 07 00:00:00 EDT 2003" , which can be converted
    to 'Date' type
    using <% Date exp_date = new Date(strDate); %> which solves my problem.
    But , when I executed same code to UNIX ,
    I got the resulted string as "2009-02-01 00:00:00.0" , which is not convertible
    to 'Date' format.
    I got the following exception , when I try to convert this resulted String to
    date format like.
    <% Date exp_date = new Date(strDate); %>
    java.lang.IllegalArgumentException
    at java.util.Date.parse(Date.java:585)
    at java.util.Date.<init>(Date.java:267)
    Finally , I need to convert the resulted string to "MMM dd, yyyy" (Feb 22, 2000)format.
    If not above method , what is the best way to get the resulted value in this "MMM
    dd, yyyy" format.
    /***** My Sample code ********/
    <es:forEachInArray array="<%=BankerMsgs%>" id="doc" type="Content" >
    <%String strDate = "";
         strDate = (String)doc.getProperty("LodedDate","ExpirationDate");     //strDate =
    "Mon Jul 07 00:00:00 EDT 2003"; // Windows
         //strDate = "2003-07-07 00:00:00.0"; // UNIX
         out.println("Original Date is :" + strDate); // In windows env I got this formatted
    result 'Mon Jul 07 00:00:00 EDT 2003' and In UNIX I got the string as '2003-07-07
    00:00:00.0'
         SimpleDateFormat formatter = new SimpleDateFormat ("MMM dd, yyyy");
         Date strDate12 = new Date(strDate);
         String strExpDate = "";
         try
              strExpDate = formatter.format(strDate12);
              out.println("Formatted Date is :" + strExpDate); // in windows I got correct
    result as 'Jul 07, 2003' and in UNIX java.lang.IllegalArgumentException
         catch(Exception e) {}
    %>     
    </es:forEachInArray>
    Any help will be much appreciated.
    thanks
    -Amar Purumandla

  • To diplay write  date format in an  input field

    I have written this code to get the curent date.
    Date  date=new  Date(System.currentTimeMillis());
    *     //String dateString=date.toString();*
        String dateString =date.getMonth()+"/";
        String dateString1=date.getDay()+"/";
        String dateString2=date.getYear()+"/";
      wdComponentAPI.getMessageManager().reportSuccess("Date "+ date);
      wdComponentAPI.getMessageManager().reportSuccess("DateSting:"+dateString);
      wdComponentAPI.getMessageManager().reportSuccess("DateSting1:"+dateString1);
      wdComponentAPI.getMessageManager().reportSuccess("DateSting2:"+dateString2);
    I am getting this output:
    date:2008-01-08
    i want  in mmddyyyy format
    01-08-2008
    plz help its giving default values
    When we try to print separately

    After writning the following code:
    Date  date=new  Date(System.currentTimeMillis());
    Format formatter = new SimpleDateFormat("mm/dd/yyyy");
    *     String s = formatter.format(date)*
    String dateString =date.getMonth()"/"date.getDay()"/"date.getYear();
    wdComponentAPI.getMessageManager().reportSuccess("Date "+ date);
      *wdComponentAPI.getMessageManager().reportSuccess("DateSting: "+dateString);
    it is giving the foloowing o/p
    0/2/1008
    thats is its not converinting it properly plzz help urgent.

  • Date format conversion from yyyy-mm-dd to mm-dd-yyyy

    Hello Experts,
    In my application one of the context element
    wdContext.currentContextElement().getEmployee_employmentDate()
    returns the value as 1978-06-15.
    Can any one suggest me how to convert this date into          06-15-1978 in webdynpro java.
    Thanks and help is really appreciate.

    Hi Bala,
    It tried this
    import java.util.*;
    import java.text.*;
    SimpleDateFormat formatter
    = new SimpleDateFormat ("mm-dd-yyyy");
    Date day = wdContext.currentContextElement().getEmployee_employmentDate()
    System.out.println("for:" + formatter.format( day ));
    ...the format is changed 1978-15-06....but now the but is overwritten by 00. it outputs 00-15-1978.
    Do I need to include any other step in between??
    Thanks,
    James

  • Need help in datetime format.

    hi there,
    currently, i have problem in converting datetime format into this pattern (yyyy-MM-dd).
    I could able to convert it in JSTL which is
    <c:set var="dates"><fmt:formatDate value="${now}" type="DATE" pattern="yyyy-MM-dd"/></c:set>
    <sql:query var="countLeave"
         sql =" SELECT * FROM VCST_EMPLOYEE_LEAVE WHERE CAST(FLOOR(CAST(leave_from AS FLOAT))AS DATETIME) = ? ">
              <sql:param value="${dates}"/>
         </sql:query>
    From the JSTL code above i would like to convert in Java code. I have no idea on how to convert it especially not converting the datetime datatype from MSSQL into String format.
    Is there any way of doing it. Thank you.

    try this
    // Format the current time.
    java.text.SimpleDateFormat formatter
    = new java.text.SimpleDateFormat ("yyyy-MM-dd");
    java.util.Date currentTime_1 = new java.util.Date();
    String dateString = formatter.format(currentTime_1);

  • Unable to get date in yyyy.MM.dd format

    Hi All
    I am unable to get date in yyyy.MM.dd format.
    I tried everything said in the previous postiongs.Nothig seem to work.
    I am getting date in yyyy-MM-dd
    This needs to be changed in said format. Also datatype should be date only.
    Regards
    Pratyush

    You can solve the problem in two ways
    First way;
    Format formatter = new SimpleDateFormat("yyyy.MM.dd");
    String s = formatter.format(date);
    OR
    Assuming your context attribute name is Date
    IWDAttributeInfo attributeInfo = wdContext.getNodeInfo().getAttribute("Date");
    attributeInfo.getDataAttribute().getScalarType().format("yyyy.MM.dd");
    Second way;
    By changing the default Language of your browser. You have to check the format of each language and choose the language that gives the date in yyyy.MM.dd format.
    Rgs,
       Dni

  • Making java.sql.Date dd.mm.yyyy format

    Hi,
    java.sql.Date format is m/d/yyyy.
    I must use  dd.mm.yyyy format.
    How can it be done?
    Thanks.

    You can use the following line of code to change the date format
    SimpleDateFormat formatter = new SimpleDateFormat("dd.MM.yyyy");
    String formattedDate = formatter.format(<Ur java.sql.Date instance>);
    Edited by: Santhosh Edla on Sep 7, 2009 5:00 PM

  • Date formatt problems..

    when i retreive a date value from oracle it is displaying in yyyy-mm-dd formatt in my date..
    but i want it to dispaly in dd-mm-yyyy formatt.
    how to convert it..in java ..
    plz asap reply me
    regards

    Hi,
    There are 2 ways to do it... In oracle you have built in functions like
    TO_CHAR (SYSDATE, 'DD-MM-YYYY')
    You can use these. Else in Java you can use SimpleDateFormat Class to convert it
    SimpleDateFormat formatter = new SimpleDateFormat ("MM-dd-MM-yyyy");
    formatter.format(date);
    Thanks and regards,
    Pazhanikanthan Periasamy,
    Senior Software Engineer,
    IT Solutions India Pvt. Ltd.,
    Madras - 600 006

  • How to format today's date?

    Hi, i am trying to get today's date (well system date) but in the next format: dd/mm/yyyy hh:mm:ss am or pm... how can i do it?
    Regards.

    Hi this is a static method that i wrote a while back...this should be able to lead you in the right direction
        public static String getCurrentDate() {
            Date wDate = new Date();
            wDate.toString();
            SimpleDateFormat formatter = new SimpleDateFormat( "dd/MM/yyyy hh:mm:ss aaa" );
            return formatter.format( wDate );
        }this will return 16/01/2002 1:13:22 PM
    this is the link to The SimpleDateFormat class from Sun.
    http://java.sun.com/products/jdk/1.1/docs/api/java.text.SimpleDateFormat.html
    tim

Maybe you are looking for