webMethods

webMethods

Join this online group to communicate across IBM product users and experts by sharing advice and best practices with peers and staying up to date regarding product enhancements.

 View Only
  • 1.  Epoch to Simple date format

    Posted Wed July 17, 2019 08:04 AM

    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.


    #Integration-Server-and-ESB
    #webMethods
    #Flow-and-Java-services


  • 2.  RE: Epoch to Simple date format

    Posted Wed July 17, 2019 09:53 AM

    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?


    #webMethods
    #Integration-Server-and-ESB
    #Flow-and-Java-services


  • 3.  RE: Epoch to Simple date format

    Posted Wed July 17, 2019 11:59 AM

    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.


    #Integration-Server-and-ESB
    #webMethods
    #Flow-and-Java-services


  • 4.  RE: Epoch to Simple date format

    Posted Wed July 17, 2019 10:21 PM

    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.


    #Flow-and-Java-services
    #Integration-Server-and-ESB
    #webMethods


  • 5.  RE: Epoch to Simple date format



  • 6.  RE: Epoch to Simple date format

    Posted Fri October 16, 2020 06:25 AM

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


    #Flow-and-Java-services
    #webMethods
    #Integration-Server-and-ESB