1

I have a requirement to add my local timezone offset to a date that I am reading from the database (i.e. the business date field below) which will then be tranformed into an epoch date (businessDate.getTime()).

public List<Long> mapRow(ResultSet rs, int rowNum) throws SQLException {
    Date businessDate = rs.getDate(BUSINESS_DATE);
    Integer numberOfTxns = rs.getInt(TRAN_COUNT);

    List<Long> count = new ArrayList<Long>();
    count.add(businessDate.getTime());
    count.add(new Long(numberOfTxns));

    return count;
}

thanks

1 Answer 1

1

You can get time zone offset this way

    int offsetInMilliseconds = TimeZone.getDefault().getOffset(date.getTime());
Sign up to request clarification or add additional context in comments.

2 Comments

So I should just be able to add that offset to my businessDate.getTime() and that will return the unix time stamp with a time zone offset?
To be exact, you will get the number of milliseconds since January 1, 1970, 00:00:00 GMT + local time zone offset in milliseconds

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.