Problems with the date type when Java reads Excel with POI

Source: Internet
Author: User

Recently read Excel with a POI and passed in the database, but there was a very wonderful problem that has been bothering me for a long time

is read when the date type appears the year and day read correctly, but the month is 00 case, I have been looking for a long time, have been unable to find the reason

When I found out today, I was careless.

Previous error code:

Date Time=new date (); Time=cell.getdatecellvalue ();//Output SimpleDateFormat df=new SimpleDateFormat in the specified format ("Yyyy/mm/dd hh: Mm:ss "); SYSTEM.OUT.PRINTLN ("Imported Time:" +time+ "   " +df.format ");

The result of this output is

Time to import: Thu 00:00:00 CST 2015 2015/00/01 12:00:00

It is the right one to read, but after formatting, there is a problem of month 00. This is a mistake in the format of the definition of a careless

SimpleDateFormat df=new SimpleDateFormat ("yyyy/mm/dd hh:mm:ss"); should read
SimpleDateFormat df=new SimpleDateFormat ("yyyy/MM/dd hh:mm:ss");

Otherwise the month is assigned by the sub-assignment, but the default is 00, so this error will occur

Problems with the date type when Java reads Excel with POI

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.