How to convert of epoch time to human readable format

Six Stars

How to convert of epoch time to human readable format

I have epoch time in my file. It may normal or in miliseconds. Please tell how to convert these epoch times in normal human readable format.

 

Epoch time examples:

1) Normal               1492430625             Indian Local time   nearly same as below time

2)In miliseconds     1492430501465       Indian Local time Mon Apr 17 2017 17:31:41


Accepted Solutions
Community Manager

Re: How to convert of epoch time to human readable format

You will need to know which value you are working with. The code I am giving you will work with time in milliseconds. In order to convert the other time unit you described, just multiply it by 1000.

 

Long myTimeAsLong = 1492430501465L;
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
System.out.println(sdf.format(new Date(myTimeAsLong)));

 ...or if you wanted to create a routine for this, you could use the following static function...

    public static String getDateFromEpoch(Long timeAsLong, String javaDatePattern){
        
    	String returnVal = null;
    	
    	if(timeAsLong!=null){
        	SimpleDateFormat sdf = new SimpleDateFormat(javaDatePattern);
        	returnVal = sdf.format(new Date(timeAsLong)); 	
        }
    	return returnVal;
    }

View solution in original post


All Replies
Community Manager

Re: How to convert of epoch time to human readable format

You will need to know which value you are working with. The code I am giving you will work with time in milliseconds. In order to convert the other time unit you described, just multiply it by 1000.

 

Long myTimeAsLong = 1492430501465L;
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
System.out.println(sdf.format(new Date(myTimeAsLong)));

 ...or if you wanted to create a routine for this, you could use the following static function...

    public static String getDateFromEpoch(Long timeAsLong, String javaDatePattern){
        
    	String returnVal = null;
    	
    	if(timeAsLong!=null){
        	SimpleDateFormat sdf = new SimpleDateFormat(javaDatePattern);
        	returnVal = sdf.format(new Date(timeAsLong)); 	
        }
    	return returnVal;
    }

View solution in original post

Six Stars

Re: How to convert of epoch time to human readable format

Thanks for this solution.. I have used below mentioned function directly in tMap worked fine for me....

(row1.epochtime == null || row1.epochtime =="") ? null : (new java.util.Date(Long.parseLong(row1.epochtime) * 1000) );



Where row1.epochtime has string of epoch time in seconds ...


Function returns time in "date" format
Five Stars

Re: How to convert of epoch time to human readable format

I need to convert "1900-01-01T00:00:00" into epoch time. It will be helpful if you have the solution? 

Employee

Re: How to convert of epoch time to human readable format

@mustafamunna 

 

Hi,

 

   I have answered your query in your post below. 

 

https://community.talend.com/t5/Design-and-Development/How-to-convert-Date-Format-into-epoch-time-by...

 

Warm Regards,
Nikhil Thampi

Please appreciate our Talend community members by giving Kudos for sharing their time for your query. If your query is answered, please mark the topic as resolved

2019 GARNER MAGIC QUADRANT FOR DATA INTEGRATION TOOL

Talend named a Leader.

Get your copy

OPEN STUDIO FOR DATA INTEGRATION

Kickstart your first data integration and ETL projects.

Download now

What’s New for Talend Summer ’19

Watch the recorded webinar!

Watch Now

Best Practices for Using Context Variables with Talend – Part 1

Learn how to do cool things with Context Variables

Blog

Migrate Data from one Database to another with one Job using the Dynamic Schema

Find out how to migrate from one database to another using the Dynamic schema

Blog

Best Practices for Using Context Variables with Talend – Part 4

Pick up some tips and tricks with Context Variables

Blog