3

Using this code

String twelveHourTime="06:00 PM";

public static DateTime convert12HourTimeTo24HourTime(String twelveHourTime) {
        DateTimeFormatter dateTimeFormatter =
                DateTimeFormat.forPattern(AppConstants.TWELVE_HOUR_TIME_FORMAT);
        DateTime dateTime = dateTimeFormatter.parseDateTime(twelveHourTime);
        return  new DateTime().withHourOfDay(dateTime.getHourOfDay())
                .withMinuteOfHour(dateTime.getMinuteOfHour());
    }

I am getting this date time:

String datetime=2017-09-15T18:00:23.153+05:30

Now I want to convert it to the US time zone.

Please suggest me how to do this.

piet.t
  • 11,718
  • 21
  • 43
  • 52
Adevelopment
  • 265
  • 3
  • 15
  • https://stackoverflow.com/questions/21258214/convert-one-time-zone-to-another-using-joda-time – Ankita Sep 15 '17 at 06:52

3 Answers3

0

Use localDateTime:

DateTime dt = new LocalDateTime(timestamp.getTime()).toDateTime(DateTimeZone.UTC);
0

you can use it by using TimeZone and SimpleDateFormat :-

            TimeZone time = TimeZone.getTimeZone("UTC");
            Calendar cal = Calendar.getInstance(time);
            final Date startDate = cal.getTime();
            SimpleDateFormat sdfAmerica = new SimpleDateFormat("dd-M-yyyy hh:mm:ss a");
            sdfAmerica.setTimeZone(TimeZone.getTimeZone("America/New_York"));
            String sDateInAmerica = sdfAmerica.format(startDate);

            edDate.setText(sDateInAmerica);
Shubham Sejpal
  • 3,556
  • 2
  • 14
  • 31
0

You can use SimpleDateFormat for conversion

  DateFormat df = new SimpleDateFormat("dd/MM/yyyy HH24:MI");
  Date date = df.parse(datetime);
UMKalaycı
  • 83
  • 9