Java processing date formats in Excel __javaee

Source: Internet
Author: User
Java Processing date formats in Excel

2011-12-23 17:34:03| Category: Java | report | font size subscribe download lofter my photo book | The date format in Excel, which is the number of days from January 1, 1900, such as converting it to a number format in 2009-12-24, becomes 40171, and reads 40171 in Java processing.
When you poi a cell in a date type in Excel, you will end up with a numeric type if you simply judge whether it is a date type. The correct way to do this is to first determine whether the cell type is otherwise numeric type, and then determine if the cell is a date format, and if so,

Create a date format, and then display the contents of the cell in this date format. If the cell is not a date format, then you can get the value of the numeric directly. The specific code is as follows:

if (0 = Cell.getcelltype ()) {

Determine whether a date type

if (hssfdateutil.iscelldateformatted (cell)) {
Used to convert to date format

Date d = cell.getdatecellvalue ();

DateFormat formater = new SimpleDateFormat ("Yyyy-mm-dd");

Str[k] = Formater.format (d);

}else{

Used to format a number, preserving only the integer portion of the number

DecimalFormat df = new DecimalFormat ("########");

Str[k] = Df.format (Cell.getnumericcellvalue ());

}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.