-1
String time ="6:30"

How can I convert it to CST time zone? If a user enters any time, it should convert into CST.

Ole V.V.
  • 81,772
  • 15
  • 137
  • 161
Akshay Kala
  • 159
  • 1
  • 1
  • 4

1 Answers1

1

Which to use?

For time zone, avoid both Date and Calendar If you are using JDK >= 8, use the new java.time.* framework. If you are using JDK < 8, use Joda Time. (The new Java 8 java.time.* framework is inspired by this library)

Applying date command

The java.util.Date has no concept of time zone, and only represents the number of seconds passed since the Unix epoch time – 1970-01-01T00:00:00Z. But, if you print the Date object directly, the Date object will be always printed with the default system time zone. Check the Date.toString() source code.

Set a time zone to DateFormat and format the java.util.Date

Check these references

https://howtodoinjava.com/java/date-time/convert-date-between-timezones

https://docs.oracle.com/javase/tutorial/datetime/iso/timezones.html

https://docs.oracle.com/javase/8/docs/api/java/util/Calendar.html

https://smartbear.com/blog/date-and-time-manipulation-in-java-using-jodatime/