apache poi  date format - xssf

Posted on 2014-02-07
Last Modified: 2014-02-19
I set up a format for my cel:
  DataFormat df = wb.createDataFormat();

style = createBorderedStyle(wb);
        styles.put("cell_pub_date", style);

Open in new window

before that I retrieve date from the database in the format cyymmdd, format it:

String year = "20" +  field.substring(1,3);
                        			String month  = field.substring(3,5);
                        			String day   = field.substring(5,7);		

          							SimpleDateFormat sf  = new SimpleDateFormat("dd.MM.yyyy");

                        			String date_s  = day + "." + month + "." + year;

                        			try {

										java.util.Date date = sf.parse(date_s);

									catch (Exception e)	 {

										System.out.println( );	

Open in new window

but the date is comletely out of whack in my excel spreadhseet
Question by:sniger
  • 2
  • 2
LVL 16

Expert Comment

ID: 39843168
What do you mean "out of whack"? What does it look like after it ends up in Excel?
LVL 86

Accepted Solution

CEHJ earned 400 total points
ID: 39843189

Open in new window

I don't know this API, but, by the looks, getFormat gets a built-in format. afaics, there isn't such a built-in one:

Author Comment

ID: 39848624

I changed the format to m/d/yy in my po style

In java se I assume it is       SimpleDateFormat sf  = new SimpleDateFormat("MM/dd/yyyy");

not for the date:    02/11/2013  I am getting in Excel:    5/29/94
                                 09/10/ 2010                                         3/9/14
LVL 16

Assisted Solution

krakatoa earned 100 total points
ID: 39848844
Let us know if you heeded CEHJ's comment first, if you please.

BTW, 'D' and 'd' are different you realise.

Author Comment

ID: 39870598
actually, it is not an issue, I had logic error and it did not set the format I expected

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
firstswap challenge 20 77
Java Loop 6 61
iterator/ListIterator approach 17 27
JAVA API design with micro service cloud in mind 1 16
An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question