简体   繁体   English

如何使用jorda时间将时区转换为UTC时区

[英]How to Convert Time Zone to UTC time zone using jorda time

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. 请建议我如何做到这一点。

使用localDateTime:

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

you can use it by using TimeZone and SimpleDateFormat :- 您可以使用TimeZone和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);

You can use SimpleDateFormat for conversion 您可以使用SimpleDateFormat进行转换

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM