How to convert Unix signed (negative) Timestamp to normal DateTime?

How to convert Unix signed (negative) Timestamp to normal DateTime?

book

Article ID: KB0081969

calendar_today

Updated On:

Products Versions
TIBCO ActiveMatrix BusinessWorks 5.x, 6.x

Description

How can one convert minutes from unix time stamp to date and time in BW. For example, time stamp 1372339860 correspond to Thu, 27 Jun 2013 13:31:00 GMT.

Issue/Introduction

How can one convert minutes from unix time stamp to date and time in BW. For example, time stamp 1372339860 correspond to Thu, 27 Jun 2013 13:31:00 GMT.

Environment

All

Resolution

It is not possible in BW to convert long type timestamp to DataTime directly, but you can achieve this by using java code. You can leverage the advantage of SimpleDateFormat available in 'java.text.SimpleDateFormat' java package.

Please use below code to convert long timestamp to DateTime.

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

public class DateTimeConversion
{
  
  public static void main(String[] args)
  {
    long unixSeconds = 1372339860;

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

    // the format of your date
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss z"); 

    // give a timezone reference for formatting (see comment at the bottom)
    sdf.setTimeZone(TimeZone.getTimeZone("GMT-4")); 
    
    String formattedDate = sdf.format(date);
    
    System.out.println(formattedDate);

  }
}
++++++++++++++++++++

Additional Information

https://stackoverflow.com/questions/732034/getting-unixtime-in-java