I am trying to convert the Date received from Server to user specific date format (IST) and returning as Date datatype. Attached the sample code and result as below

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

public class ServerToClientDateTime {
    public static void main(String[] args) {
        try {
            String clientSpecificFormat = "yyyy-MM-dd HH:mm:ss";
            String clientTimezone1 = "America/New_York";
            String clientTimezone2 = "Asia/Kolkata";
            Date date = new Date();
            System.out.println(new Date());
            SimpleDateFormat dateFormat = new g(clientSpecificFormat);
            TimeZone americaNewyork = TimeZone.getTimeZone(clientTimezone1);
            TimeZone asiaKolkata = TimeZone.getTimeZone(clientTimezone2);
            dateFormat.setTimeZone(americaNewyork);

            System.out.println("\namerica/ newyork:" + dateFormat.format(date));
            System.out.println("Date format :" + dateFormat.parse(dateFormat.format(date)));

            dateFormat.setTimeZone(asiaKolkata);
            System.out.println("\nAsia/ Kolkata:" + dateFormat.format(date));
            System.out.println("Date format :" + dateFormat.parse(dateFormat.format(date)));
        } catch (Exception exp) {
            System.out.println(exp);
        }
    }
    
}

Result for the Program as

Wed Aug 09 11:57:46 IST 2023

america/ newyork:2023-08-09 02:27:46
Date format :Wed Aug 09 11:57:46 IST 2023

Asia/ Kolkata:2023-08-09 11:57:46
Date format :Wed Aug 09 11:57:46 IST 2023

why America/New_York return same as GMT after parsing, how to get the expected IST date format.

Thanks

0

There are 0 best solutions below