Java TimeZone Change convertTimezone(Date date, String destZone, String dateFormat)

Here you can find the source of convertTimezone(Date date, String destZone, String dateFormat)

Description

Converts a date into another timezone.

License

Open Source License

Parameter

Parameter Description
date a parameter
destZone a parameter
dbFormat a parameter

Declaration

public static String convertTimezone(Date date, String destZone, String dateFormat) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.text.DateFormat;
import java.text.SimpleDateFormat;

import java.util.Date;

import java.util.TimeZone;

public class Main {
    /**// w w w.java 2  s.com
    * Converts a date into another timezone.
    * TODO: not sure that works - needs testing.
    * @param date
    * @param destZone
    * @param dbFormat
    * @return
    */
    public static String convertTimezone(Date date, String destZone, String dateFormat) {
        DateFormat df = new SimpleDateFormat(dateFormat);
        df.setTimeZone(TimeZone.getTimeZone(destZone));
        return df.format(date);
    }
}