how do i fetch date timestamp as UTC

I am storing date timestamps in DB as UTC value, while retrieving it back i need to make as UTC time and need to convert to specific timezone value.

i.e.
2015-05-01 00:09:30:00 UTC time
need to convert to IST(Or other timezone)

resultSet.getDate("VisitDate")

please help on this.

Java 8

You can use a ZonedDateTime set to UTC and then translate it to a LocalDateTime using something like…

java.sql.Timestamp ts = resultSet.getTimestamp("VisitDate");
ZonedDateTime utcDateTime = ZonedDateTime.ofInstant(ts.toInstant(), ZoneId.of("UTC"));
LocalDateTime localDateTime = utcDateTime.withZoneSameInstant(ZoneId.systemDefault()).toLocalDateTime();

Obviously, I’ve use ZoneId.systemDefault() in the example (convert the zoned date/time to local date/time), but you can pass what ever zone you want/need

Joda-Time

And similarly with Joda-Time if you’re not using Java 8

java.sql.Timestamp ts = resultSet.getTimestamp("VisitDate");
LocalDateTime utcDateTime = new LocalDateTime(ts, DateTimeZone.UTC);
DateTime hereDateTime = utcDateTime.toDateTime(DateTimeZone.getDefault());

As you said while lodaing into DB you are setting as UTC timezone, But when retriving the Timezone back from DB it can not be UTC again as DB wont store Timezone information for more details checkout this link
Dealing with Timezones in DB

So according to that it might return the Timezone of your local JVM or DB server Timezone settings.

Anyway to change the Timezone as mentioned in other answer you can Use SimpleDateFormat

  final SimpleDateFormat sdf = new SimpleDateFormat(DATEFORMAT);
sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
final String utcTime = sdf.format(new Date());
private final static String DATEFORMAT = "yyyy-MM-dd HH:mm:ss";
public static String getCurrentTimeInUTC(){

    final SimpleDateFormat sdf = new SimpleDateFormat(DATEFORMAT);
    sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
    final String utcTime = sdf.format(new Date());


    return utcTime;

}

U can change the UTC string to any known timezone string to get that formate. Do vote if this is helpful.
for changing the timezone you can use this function

public static String getLocalTime(String timeZone) throws ParseException{
     DateFormat formatter = null;
        Date convertedDate = null;

        DateFormat outputFormat=new  SimpleDateFormat(DATEFORMAT);
        formatter = new SimpleDateFormat(DATEFORMAT);
        formatter.setTimeZone(TimeZone.getTimeZone(timeZone));
        convertedDate = (Date) formatter.parse(getCurrentTimeInUTC());
        return outputFormat.format(convertedDate);
}

Enjoy 🙂