# Java Service to convert Epoch Time to Simple Date Time Format

**URL:** <https://techcommunity.softwareag.com/t/java-service-to-convert-epoch-time-to-simple-date-time-format/237276>\
**Category:** Knowledge base\
**Tags:** java, epoch-time, unix-epoch\
**Created:** [July 18, 2019, 3:17am UTC](https://techcommunity.softwareag.com/t/java-service-to-convert-epoch-time-to-simple-date-time-format/237276 "2019-07-18T03:17:12Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mahesh\_K\_Sreenivas](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/mahesh_k_sreenivas/32/299_2.png) [@Mahesh\_K\_Sreenivas](https://techcommunity.softwareag.com/u/Mahesh_K_Sreenivas)\
**Post date:** [July 18, 2019, 3:17am UTC](https://techcommunity.softwareag.com/t/java-service-to-convert-epoch-time-to-simple-date-time-format/237276/1 "2019-07-18T03:17:12Z")

</div>

## What is epoch time?

The&nbsp;Unix epoch&nbsp;(or&nbsp;Unix time&nbsp;or&nbsp;POSIX time&nbsp;or&nbsp;Unix timestamp) is the number of seconds that have elapsed since January 1, 1970 (midnight UTC/GMT), not counting leap seconds (in ISO 8601: 1970-01-01T00:00:00Z). Literally speaking the epoch is Unix time 0 (midnight 1/1/1970), but 'epoch' is often used as a synonym for Unix time. Some systems store epoch dates as a signed 32-bit integer, which might cause problems on January 19, 2038 (known as the Year 2038 problem or Y2038). The converter on this page converts timestamps in seconds (10-digit), milliseconds (13-digit) and microseconds (16-digit) to readable dates.

| Human-readable time&nbsp; | Seconds |
| --- | --- |
| 1 hour | 3600 seconds |
| 1 day | 86400 seconds |
| 1 week | 604800 seconds |
| 1 month (30.44 days)&nbsp; | 2629743 seconds |
| 1 year (365.24 days)&nbsp; | &nbsp;31556926 seconds |

More details on&nbsp;[https://www.epochconverter.com/](https://www.epochconverter.com/)

Here is the java utility service to convert&nbsp;Epoch Time to Simple Date Time Format. Create a java service "GetDateTimeByEpoch" and define the below input and output, copy-paste the code as provided below, add the required imports:

Input:&nbsp;epochTime (String)

Output:&nbsp;dateTimeStamp (String)

```
=================================================

import java.util.Locale; 
import java.text.SimpleDateFormat; 
import java.time.LocalDateTime; 
import java.time.ZoneOffset; 
import java.time.format.DateTimeFormatter; 
import java.util.Date; 

=================================================

IDataCursor pipelineCursor = pipeline.getCursor();

String epochTime = (String) IDataUtil.get(pipelineCursor, "epochTime");

//long unix_seconds = 1563370941;  

long unix_seconds = Long.parseLong(epochTime);

//convert seconds to milliseconds
  
Date date = new Date(unix_seconds * 1000 L);

// format of the date  

SimpleDateFormat jdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

String java_date = jdf.format(date);

//System.out.println("\n" + java_date + "\n");

IDataUtil.put(pipelineCursor, "dateTimeStamp", java_date);

pipelineCursor.destroy();
```

Note, if the input&nbsp;epochTime=1563370941000 (assuming that this timestamp is in milliseconds), then you might have to stripe the trailing zeros by dividing by 1000.&nbsp;

> **Further Read:**  
> More on Java Service: learn how to convert StringList/DocList/StringTable to XLS here: [Java Service to convert StringList and DocList to XLS - ToExcel Utility](https://techcommunity.softwareag.com/t/java-service-to-convert-stringlist-and-doclist-to-xls-toexcel-utility/237254)
