How to Convert Time Zone to UTC time zone using jorda time

java android

84 观看

3回复

110 作者的声誉

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.

作者: Adevelopment 的来源 发布者: 2017 年 9 月 15 日

回应 3


0

0 作者的声誉

Use localDateTime:

DateTime dt = new LocalDateTime(timestamp.getTime()).toDateTime(DateTimeZone.UTC);
作者: user3906011 发布者: 2017 年 9 月 15 日

0

1581 作者的声誉

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 发布者: 2017 年 9 月 15 日

0

63 作者的声誉

You can use SimpleDateFormat for conversion

  DateFormat df = new SimpleDateFormat("dd/MM/yyyy HH24:MI");
  Date date = df.parse(datetime);
作者: UMKalaycı 发布者: 2017 年 9 月 15 日
32x32