Convert GMT to IST in java?

前端 未结 4 562
旧巷少年郎
旧巷少年郎 2021-01-21 11:12

I have a GMT field in which the user enter a time to be converted to IST (for eg: in hour field 18, minute field 30, in session field am/pm). I need to get those inputs and conv

4条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-21 11:42

    When I add the below code, it worked for me.

    DateFormat utcFormat = new SimpleDateFormat("yyyy-MM-dd-HH-mm");
                                utcFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
                                DateFormat indianFormat = new SimpleDateFormat("dd-HH-mm");
                                utcFormat.setTimeZone(TimeZone.getTimeZone("IST"));
                                Date timestamp = utcFormat.parse("2019-04-26-19-00");
                                String istTime = indianFormat.format(timestamp);
    

提交回复
热议问题