Convert GMT to IST in java?

前端 未结 4 563
旧巷少年郎
旧巷少年郎 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:51

    Well, joda-time is easier. Try something like this

    DateTime dt = new DateTime(,,, ,, , );
    DateTime dtIST = dt.withZone(DateTimeZone.forTimeZone(TimeZone.getTimeZone("IST");
    

    Note here that the use of the three letter abbreviation is deprecated and that time zones should be referred to like "America/Los_Angeles" refers to PST.I haven't the time to get the corrsesponding for IST right now but something should be left as an exercise to the reader!

    UPDATE: As Basil Bourque states in the comments, Joda-Time is in maintenance mode. Use java.time instead.

提交回复
热议问题