Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

apache poi  date format - xssf

Posted on 2014-02-07
5
Medium Priority
?
1,522 Views
Last Modified: 2014-02-19
I set up a format for my cel:
  DataFormat df = wb.createDataFormat();

style = createBorderedStyle(wb);
        style.setAlignment(CellStyle.ALIGN_RIGHT);
        style.setFont(font1);
        style.setDataFormat(df.getFormat("dd.MM.yyyy"));
        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;
                        			System.out.println(date_s);

                        			try {

										java.util.Date date = sf.parse(date_s);
										System.out.println(date.toString());     
										c.setCellValue(date);
										c.setCellStyle(styles.get("cell_pub_date"));
									}

	
									catch (Exception e)	 {

										System.out.println( );	
									}	

Open in new window



but the date is comletely out of whack in my excel spreadhseet
0
Comment
Question by:sniger
  • 2
  • 2
5 Comments
 
LVL 17

Expert Comment

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

Accepted Solution

by:
CEHJ earned 1600 total points
ID: 39843189
style.setDataFormat(df.getFormat("dd.MM.yyyy"));

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:

http://poi.apache.org/apidocs/org/apache/poi/ss/usermodel/BuiltinFormats.html
0
 

Author Comment

by:sniger
ID: 39848624
krakatoa,

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
0
 
LVL 17

Assisted Solution

by:krakatoa
krakatoa earned 400 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.
0
 

Author Comment

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

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
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…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses

916 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