Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/205.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何使用jorda Time将时区转换为UTC时区_Java_Android - Fatal编程技术网

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

Java 如何使用jorda Time将时区转换为UTC时区,java,android,Java,Android,使用此代码 String twelveHourTime="06:00 PM"; public static DateTime convert12HourTimeTo24HourTime(String twelveHourTime) { DateTimeFormatter dateTimeFormatter = DateTimeFormat.forPattern(AppConstants.TWELVE_HOUR_TIME_FORMAT);

使用此代码

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());
    }
我得到这个日期的时间:

String datetime=2017-09-15T18:00:23.153+05:30
现在我想把它转换成美国时区

请建议我如何执行此操作。

使用localDateTime:

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

您可以使用时区和SimpleDataFormat来使用它:-

            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);

可以使用SimpleDataFormat进行转换

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

这个我已经试过了它不起作用了它的giving@rta1我将在哪里设置我的日期时间2017-09-15T18:00:23.153+05:30@Shubham Sejpali刚刚更新了代码现在通过重新处理整个代码来试一下好了等等让我检查一下2017-09-15T18:00:23.153+05:30我将在哪里通过这个你能告诉我你需要哪个国家的时间吗?我必须转换2017-09-15T18:00:23.153+05:30此美国时间格式