How to convert excel number to date in java

What you will learn here about java

  • How to convert excel number to date in java

How to convert excel number to date in java

Here we will see how to convert 5 digit excel number in date. Please follow the following steps to know how to convert excel number to date in java

1)First create a simple maven project

2)Add apache poi dependency in your pom.xml which is shown below

<dependency>
	<groupId>org.apache.poi</groupId>
	<artifactId>poi</artifactId>
	<version>4.1.2</version>
</dependency>

3)Below code will convert excel 5 digit number into date format which is shown below

import java.text.SimpleDateFormat;
import java.util.Date;

import org.apache.poi.ss.usermodel.DateUtil;

public class Number2DateExcel {
	
	public static void main(String[] args) {
	
		//44573.00 is excel 5 digit number
		Date date = DateUtil.getJavaDate(44573.00);
		System.out.println("Converted date -> "+ new SimpleDateFormat("DD/MM/YYYY").format(date));
	}

}

4)Once you run above code you will see following kind of output
Converted date -> 12/01/2022

You may also like...