日期时间本地时区到 UTC 和 UTC 到 Android 中其他一些选定的时区转换



我正在开发一个安卓应用程序。在我的应用程序中,我优先存储了登录的本地日期时间,并显示在用户配置文件页面中。几天后,我将移动时区更改为澳大利亚。现在我需要将现有的本地日期时间转换为澳大利亚时区日期时间并显示在配置文件页面中。可能吗。给我看代码片段。您的帮助将不胜感激。提前谢谢。

String inputText = "2017-05-17 15:50:00";
    SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss",Locale.ENGLISH);
    df.setTimeZone(TimeZone.getTimeZone("Etc/UTC"));
    SimpleDateFormat outputFormat =
            new SimpleDateFormat("MMM dd, yyyy h:mm a");
    // Adjust locale and zone appropriately
    Date date = null;
    try {
        date = df.parse(inputText);
    } catch (ParseException e) {
        e.printStackTrace();
    }
    String outputText = outputFormat.format(date);
    System.out.println(outputText);

试试这个代码..它可能会有所帮助

最新更新