Epoch to Simple date format

Hello All,

I have a requirement to maintain the start time of scheduled tasks.

nextRun service out of pub.scheduler:getTaskInfo provides date in epoch format:
nextRun - date and time that the task is scheduled to run. The date and time is expressed as the number of milliseconds from
January 1, 1970, 00:00:00 GMT.

I need to get the date format for the nextRun in dd-mm-yyyy hh:mm:ss.SSSSSS
I am trying to use pub.date:dateTimeFormat, but not sure of the currentPattern service in.

inString: 1563442200000

currentPattern:

newPattern: dd-mm-yyyy hh:mm:ss.SSSSSS

Request assistance at the earliest.

Thanks.

Not sure if there is a patter for Epoch, but you can use the below code snippet which will return you the date time in GMT


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


IDataCursor pipelineCursor = pipeline.getCursor();
			String	myTimeAsLong = (String) IDataUtil.get( pipelineCursor, "myTimeAsLong" );
			
			long num = Long.parseLong(myTimeAsLong);
			
			LocalDateTime dateTime = LocalDateTime.ofEpochSecond(num, 0, ZoneOffset.UTC);
			DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd-MM-yyyy hh:mm:ss.SSSSSS", Locale.ENGLISH);
			String formattedDate = dateTime.format(formatter);
			System.out.println(formattedDate); 
				
		IDataUtil.put( pipelineCursor, "dateTimeStamp", formattedDate );
		pipelineCursor.destroy();

Input:
myTimeAsLong=1563362173

Output
dateTimeStamp=17-07-2019 11:16:13.000000

Use the https://www.epochconverter.com/ for testing.Let me know how you go?

Hello Mahesh,

Thank you for your prompt assistance.

I tried creating a java service as per the code snippet shared by you.

For the sample value provided by you, it is giving proper output.
But when I provide the epoch time as per the nextRun value = 1563370941000 of pub.scheduler:getTaskInfo.
It provides junk value - 04-04-+51511 01:50:00.000000

Same value when provided in https://www.epochconverter.com/ for testing gives proper response.

You have to remove trailing zeros (example 3 zeros exists in your input (assuming that this timestamp is in milliseconds), you can write a simple code for this in flow/java) and pass it to the previous code and see what is the output you get?

You can also try this code below that outputs in local date time: Check all the possible input values and code it accordingly.


IDataCursor pipelineCursor = pipeline.getCursor();  
		            String  myTimeAsLong = (String) IDataUtil.get( pipelineCursor, "myTimeAsLong" );  
		              
		            
		            //long unix_seconds = 1563370941;
		            
		            long unix_seconds = Long.parseLong(myTimeAsLong); 
		            
		            //convert seconds to milliseconds
		            Date date = new Date(unix_seconds*1000L); 
		            // 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();

Make sure to import the below classes:

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;

Let me know if you have any questions, meanwhile I will post an article/blog on the same.

Article link:

http://techcommunity.softwareag.com/pwiki/-/wiki/Main/Java+Service+to+convert+Epoch+Time+to+Simple+Date+Time+Format

Hi when I am trying with the above logic it is giving wrong date.Have any one tried this