1

I am trying to do it this way 1. Get my time current time and time zone. 2. I know time zone of that specific country from Google. 3. Calculate difference in time zones. 4. Subtract this difference from current time. This will give me time in other country. I am stuck at step 3 and 4. I get current time like this

Date d = new Date();
CharSequence s = DateFormat.format("hh:mm:ss", d.getTime());

and time zone like this

Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("GMT"),
            Locale.getDefault());
    Date currentLocalTime = calendar.getTime();
    SimpleDateFormat date = new SimpleDateFormat("Z");
    String localTime = date.format(currentLocalTime);

let time zone of specific country be represented by string x.Now how do i get localTime - x and then currentTime - (localTime - x).

user3714283
  • 31
  • 1
  • 7
  • possible duplicate of [Joda-Time DateTime.toDate() reverts back timezone](http://stackoverflow.com/questions/24044810/joda-time-datetime-todate-reverts-back-timezone) – Basil Bourque Jun 07 '14 at 03:51
  • java.util.Date dateIn = new java.util.Date(); DateTime dateTimeUtc = new DateTime( dateIn, DateTimeZone.UTC ); This gives me error that DateTime can't be resolved to a type. – user3714283 Jun 07 '14 at 03:58
  • Asked and answered many times on StackOverflow. Search for "Joda DateTimeZone" or "ZonedDateTime". – Basil Bourque Jun 07 '14 at 04:04
  • That code quote refers to Joda-Time, an excellent date-time library. So you need to include the jar in your project, and add `import` statements for the `org.joda` package. We use Joda-Time because the java.util.Date and .Calendar classes bundled with Java are notoriously troublesome and should be avoided. – Basil Bourque Jun 07 '14 at 04:08

1 Answers1

1

x is the time zone id, there are a link of a list of them. Only need to feed the gettimeZone("with the time zone id") with the time zone of the city you want to know the time (I'm saying city because there are country with a lot of time zones like US or Russia).

TimeZone tz = TimeZone.getTimeZone("x")

http://garygregory.wordpress.com/2013/06/18/what-are-the-java-timezone-ids/

Narksh
  • 11
  • 2