2017  Kodetalk | Feedback | Privacy Policy | Terms | About
userimage

how to convert local timezone date time to other timezone date and time using java.

i need to convert local timezone date time to other timezone date and time using java.  how can i do that.
userimage

you can use below way to get your result:


package com.kodetalk.datetime;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;

public class ChangeTimeZone {
    public static void main(String[] argv) throws ParseException {

        SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy hh:mm");

        String dateInString = "24/12/2015 10:15";
        Date date = formatter.parse(dateInString);

        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd/MM/yyyy hh:mm");
        TimeZone timeZone = TimeZone.getTimeZone("America/New_York");
        simpleDateFormat.setTimeZone(timeZone);
       
        String stringDate = simpleDateFormat.format(date);
        Date dateInAmerica = formatter.parse(stringDate);

        System.out.println("Formated Date Time : " + formatter.format(dateInAmerica));
    }
}

Answer is